[EDIT] I am changing this to more concisely explain what my problem was, after having more precisely pinpointed the issue.
I am working on core data for my app, but am stumped. It hangs in this method every time. No crashes, no logs, no nothing. It just hangs.
- (void)insertNewObject:(id)sender
{
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
Section *newSection = (Section *)newObject;
newSection.title = @"inserted";
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
I discovered that if I put NSLogs in these two delegate methods:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
they just keep getting called infinite number of times.
Ok, I figured it out. I was creating an infinite loop.
This delegate method gets called:
Then this eventually gets called because I called [self.tableView beginUpdates]; in the delegate method.
Then this delegate method:
The the problem is that I was actually changing the NSManagedObject’s attributes while it was updating the content
this caused controllerWillChangeContent: to be called once again creating a loop that just goes round and round.