I'm having problems with the master data / NSFetchedResultsController. I am not quite sure where the error is, as the message is rather vague.
I had a problem inserting multiple objects when the selected result controller has no objects. The following code will crash with the following error if I try to insert multiple objects that are not already selected. This is not a failure if I use it to insert a single object, and it does not crash if there are already objects.
The failure occurs using the save: method. headers in NSArray, and in this example it contains 5 lines.
Serious application error. an exception was detected during a change in master data processing: * - [NSCFArray objectAtIndex:]: index (4) outside bounds (1) with userInfo (null) * Application terminated due to an uncaught exception "NSRangeException", reason: '** * - [NSCFArray objectAtIndex:]: index (4) outside (1) '
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:&error])
{
NSLog(@"Unresolved error %@ %@", error, [error userInfo]);
abort();
}
source
share