Hi there, Fairly new to iPhone dev. My app uses Core Data, and at one point I'm attempting to save some data during an NSFetchedResultsControllerDelegate method:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
I'm getting most of this right out of Apple's documentation on the subject. The delete action looks like so:
case NSFetchedResultsChangeDelete:
[managedObjectContext deleteObject:anObject];
NSError *error;
if (![managedObjectContext save:&error]) {
NSLog(@"WTF? %@", [error description]);
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
Now, when I do this, the object in question will be deleted after the inevitable crash. So something right is happening. The crash is interesting, though:
Serious application error. Exception was caught during Core Data change processing:Failed to process pending changes before save. The context is still dirty after 100 attempts. Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler. with userInfo (null)
2010-02-09 23:02:03.931 app2[26664:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to process pending changes before save. The context is still dirty after 100 attempts. Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler.'
My research has turned up some very limited results -- good thing I have here to document this, eh? :-) But my gut is saying that the MOC is being written to elsewhere in my controller, though I can find no evidence of that happening. The viewDidLoad method has the NSFetchedResultsController being used to get the initial data, but that's it.
Any suggestions on what might be wrong here? As usual, your community-based hive mind is very much appreciated!
Cheers, Aaron