I am writing an iPad application that displays articles and uploads new articles in a separate NSOperation in a queue and inserts them into the master data. Currently, I have a separate context for the operation created in the main operation method and using the same coordinator as the main context. I use the same template that was suggested for listening in this operation for NSManagedObjectContextDidSaveNotification, and then calls mergeChangesFromContextDidSaveNotification in the context of the main thread. The problem is that I get this error:
2011-01-27 07:26:02.574 Zagazine[12298:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object persistent store is not reachable from this NSManagedObjectContext coordinator' *** Call stack at first throw: ( 0 CoreFoundation 0x3284b987 __exceptionPreprocess + 114 1 libobjc.A.dylib 0x31aca49d objc_exception_throw + 24 2 CoreData 0x3549d07b _PFRetainedObjectIDCore + 638 3 CoreData 0x3549cdfb - [NSManagedObjectContext(_NSInternalAdditions) _retainedObjectWithID:] + 14 4 CoreData 0x354bf85b -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:] + 2170 5 CoreFoundation 0x327e9bbf -[NSObject(NSObject) performSelector:withObject:] + 22 6 Foundation 0x320fd795 __NSThreadPerformPerform + 268 7 CoreFoundation 0x328017dd __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12 8 CoreFoundation 0x327d34fb __CFRunLoopDoSources0 + 194 9 CoreFoundation 0x327d2e5b __CFRunLoopRun + 230 10 CoreFoundation 0x327d2c87 CFRunLoopRunSpecific + 230 11 CoreFoundation 0x327d2b8f CFRunLoopRunInMode + 58 12 GraphicsServices 0x3094a4ab GSEventRunModal + 114 13 GraphicsServices 0x3094a557 GSEventRun + 62 14 UIKit 0x32c14329 -[UIApplication _run] + 412 15 UIKit 0x32c11e93 UIApplicationMain + 670 16 ArticleApp 0x0000233f main + 70 17 ArticleApp 0x000022f4 start + 40 ) terminate called after throwing an instance of 'NSException' Program received signal: "SIGABRT".
This interesting part is that this error only occurs when you first start the application after installing it. All subsequent launches after installing it work fine. Does anyone know why this error occurs and why it only happens during initial installation.
Also, this is how I merge the context, this is called the background thread when it receives the notification:
- (void)mergeChanges:(NSNotification *)notification { AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; NSManagedObjectContext *mainContext = [appDelegate managedObjectContext];
ios objective-c iphone ipad core-data
marchinram
source share