title: Trying to sort Core Data objects by date in table view
body: <p>I've got a Core Data setup where each object has an NSDate, and a method that returns the date as a string (i.e., "12/15/2009"). The objects are displayed in a table view, and I'd like to sort them into sections based on the date string. Apple's example code in the CoreDataBooks app uses this line:</p>
  
  <pre><code>NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"author" cacheName:@"Root"];
  </code></pre>
  
  <p>So I altered it and used this line in my project:</p>
  
  <pre><code>NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"workoutDateString" cacheName:@"Root"];
  </code></pre>
  
  <p>Where "workoutDateString" is the method that returns a workout object's date as a string. My core data setup works perfectly when I leave sectionNameKeyPath as nil, and I also know that my workoutDateString method works correctly. But when I set sectionNameKeyPath to workoutDateString, not only does it not display the section titles, but every time I add a workout object, the program crashes with this error:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1.  The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).'</p>
  </blockquote>
  
  <p>This is my first real iPhone project and I don't have any experience with setting up table sections. And trust me, I have spent quite a bit of time on Google looking for solutions.</p>