CoreData: Error: A serious application error. An exception was found while processing Core Data

Hi, I'm getting a glitch

when I try to insert 1000 records in db in the background, I get the following exception: CoreData: error: Serious application error . An exception was found while processing changes to Core Data.
This is usually an observer error.

 NSManagedObjectContextObjectsDidChangeNotification. -[__NSCFSet addObject:]: attempt to insert nil with userInfo (null)2013-11-19 09:41:19.587 3pTalk[7487:907] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet addObject:]: attempt to insert nil' 

I used code to insert objexts

 dispatch_queue_t myBackgroundQ = dispatch_queue_create("com.sample.addressbook", NULL); // Could also get a global queue; in this case, don't release it below. dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC); dispatch_after(delay, myBackgroundQ, ^(void){ [self userAddressbook]; }); dispatch_release(myBackgroundQ); [self performSelectorOnMainThread:@selector(startSyncLoader) withObject:nil waitUntilDone:YES]; 
+6
source share
2 answers

Do not access the same database (Persistent Store Coordinator) from 2 threads (main, background) simultaneously with one context. This is not recommended. this causes the application to crash.

create an NSManagedContext object and set persistentstoreCoordinator.

  dispatch_queue_t request_queue = dispatch_queue_create("com.xxx.ScsMethod", NULL); dispatch_async(request_queue, ^{ NSPersistentStoreCoordinator *mainThreadContextStoreCoordinator = [context persistentStoreCoordinator]; // NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init]; // [context setPersistentStoreCoordinator:mainThreadContextStoreCoordinator];} 
+16
source

Are you accessing the database from two threads simultaneously ?, using the same context? This may be the reason. see this question

Problems adding to NSMutableArray: trying to insert a null object in 10

+2
source

Source: https://habr.com/ru/post/958360/


All Articles