title: Core data / NSFetchedResultsController error
body: <p>I'm having some trouble with core data / NSFetchedResultsController. I'm not entirely sure where the error is as the message is quite vague. </p>
  
  <p>I have an issue with inserting more than one object when the fetched results controller has no objects fetched. The following code will crash with the following error if I try and insert several objects with none fetched already. It doesn't crash if I use it to insert one object, and it doesn't crash if there are already objects fetched. </p>
  
  <p>The crash occurs on the save: method. titles in an NSArray and in this example it contains 5 strings.</p>
  
  <blockquote>
    <p>Serious application error.  Exception
    was caught during Core Data change
    processing: <strong>* -[NSCFArray
    objectAtIndex:]: index (4) beyond
    bounds (1) with userInfo (null)
    *</strong> Terminating app due to uncaught exception 'NSRangeException', reason:
    '*** -[NSCFArray objectAtIndex:]:
    index (4) beyond bounds (1)'</p>
  </blockquote>
  
  <pre><code>NSEnumerator *titleEnumerator = [titles objectEnumerator];
  NSString *title;
  NSMutableArray *tasks = [NSMutableArray array];
  Todo *todo;
  
  while(title = [titleEnumerator nextObject])
  {
      todo = (Todo *)[NSEntityDescription insertNewObjectForEntityForName:@"Todo" inManagedObjectContext:managedObjectContext];
      todo.title = title;
      todo.state = [NSNumber numberWithInteger:TodoStateIncomplete];
      todo.priority = [NSNumber numberWithInteger:TodoPriorityNormal];
      todo.timeStamp = [NSDate date];
      todo.dueDate = [NSDate distantFuture];
  }
  
  NSError *error;
  
  if(![managedObjectContext save:&amp;error])
  {
      NSLog(@"Unresolved error %@ %@", error, [error userInfo]);
      abort();
  }
  </code></pre>