CoreData error: attempt to recursively call -save: on the context aborted

I am getting this error when the app attempt to save change to local store:

*** ERROR *** Unresolved error Error


Domain=NSCocoaErrorDomain Code=132001 (null) UserInfo={message=attempt to recursively call -save: on the context aborted, stack trace=(

0 CoreData -[NSManagedObjectContext save:]



The syntax used:

NSError *error;

if (![managedObjectContext save:&error]) { // Commit the change.

NSLog(@"*** ERROR *** Unresolved error %@, %@", error, [error userInfo]);

}

Although Xcode shows stack trace as if the program crashed, it didn't and the program continue to execute as expected. The changes are made to the local store as well. Other the error and the stack trace there is no really any evident that there is any problem.

This happens only in Xcode 8 Beta (currently using beta 5).

Any idea why I am getting this error?

Did you ever figure out why this was happening and/or find a solution?

I am also facing this issue on iOS 10

I was getting this error on ios10 only because I had a saveContext call in NSManagedObjectContextObjectsDidChange

ios9 and below has always been fine. Maybe it was still incorrect practice but didn't cause a crash.

- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath

I had the same problem with the Xcode8/ios10. The problem was due to a call to save core data context inside the following method.


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {

[self methodCallingSaveContext];

}


The methodCallingSaveContext/0 calls the save core data context. In order to break the recursive call I rewrote the method in the following way:


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {

dispatch_async(dispatch_get_main_queue(), ^{

[self methodCallingSaveContext];

});

}


Now everithing is working again.

CoreData error: attempt to recursively call -save: on the context aborted
 
 
Q