CoreData: error: Serious application error. Exception was caught during Core Data change processing

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

Hi I'm getting crash,

when i'm trying to insert 1000 records into db in back ground, i'm getting following exception: CoreData: error: Serious application error. Exception was caught during Core Data change processing.
This is usually a bug within an observer of

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 the code for inserting 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]; 

回答1:

Dont access same Database(Persistent Store Coordinator) from 2 threads(Main,Background) simultaneously with one context. This is not recommended. it causes App Crash.

create 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];} 


回答2:

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

Problems Adding to NSMutableArray: attempt to insert nil object at 10



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!