Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData ManagedObjectContext Recursive Save Error

Some users of mine are encountering a CoreData error when performing a save. I haven't been able to find any information online about this error or how to symbolicate the stack trace.

The error message is attempt to recursively call -save: on the context aborted, stack trace, with the full error message below.

Doe anyone have any hints or ideas on how to figure out what is going wrong?

Error Domain=NSCocoaErrorDomain Code=132001 "(null)" UserInfo={message=attempt to recursively call -save: on the context aborted, stack trace=(
0   CoreData                            0x0000000188cbe70c  + 164
1   Primetime                           0x0000000100077ea4 Primetime + 130724
2   Primetime                           0x00000001000ae988 Primetime + 354696
3   Primetime                           0x0000000100081674 Primetime + 169588
4   Primetime                           0x00000001000802ac Primetime + 164524
5   CoreData                            0x0000000188d8bbd4  + 4568
6   CoreData                            0x0000000188d8a9ec  + 124
7   CoreFoundation                      0x00000001869ac24c  + 20
8   CoreFoundation                      0x00000001869ab950  + 400
9   CoreFoundation                      0x00000001869ab6cc  + 60
10  CoreFoundation                      0x0000000186a187bc  + 1504
11  CoreFoundation                      0x00000001868ef32c _CFXNotificationPost + 376
12  Foundation                          0x000000018738296c  + 68
13  CoreData                            0x0000000188cc16e8  + 724
14  CoreData                            0x0000000188d43ca4  + 1336
15  CoreData                            0x0000000188cbfd04  + 2116
16  CoreData                            0x0000000188cbe808  + 416
17  Primetime                           0x0000000100077ea4 Primetime + 130724
18  Primetime                           0x0000000100089968 Primetime + 203112
19  Primetime                           0x00000001001d47c0 Primetime + 1558464
20  libdispatch.dylib                   0x0000000186459058  + 24
21  libdispatch.dylib                   0x0000000186459018  + 16
22  libdispatch.dylib                   0x000000018645dbcc _dispatch_main_queue_callback_4CF + 1000
23  CoreFoundation                      0x00000001869bfc48  + 12
24  CoreFoundation                      0x00000001869bd834  + 1660
25  CoreFoundation                      0x00000001868ed764 CFRunLoopRunSpecific + 292
26  GraphicsServices                    0x00000001882f0198 GSEventRunModal + 180
27  UIKit                               0x000000018c8668d0  + 664
28  UIKit                               0x000000018c86163c UIApplicationMain + 208
29  Primetime                           0x00000001000ada1c Primetime + 350748
30  libdyld.dylib                       0x00000001864905b8  + 4
like image 961
duncanc4 Avatar asked Aug 08 '16 15:08

duncanc4


People also ask

What is the managed object context?

The managed object context represents a scratch pad where you create the managed objects. The context tracks changes to and relationships between objects.

What happens when save fails on the nsmanagedobjectcontext?

The call to save on the NSManagedObjectContext accepts a reference to an NSError variable and always returns either a success or a fail. If the save fails, it is important to display the error condition so that it can be corrected.

What happens when you save changes in a context?

When you save changes in a context, the changes are only committed “one store up.” If you save a child context, changes are pushed to its parent. Changes are not saved to the persistent store until the root context is saved. (A root managed object context is one whose parent context is nil .)

How are changes to a managed object stored in memory?

Changes to managed objects are held in memory, in the associated context, until that context is saved to one or more persistent stores. A single managed object instance exists in one and only one context, but multiple copies of an object can exist in different contexts.


1 Answers

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

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 everything is working again.

like image 62
chiarotto.alessandro Avatar answered Oct 07 '22 05:10

chiarotto.alessandro