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

前端 未结 2 507
借酒劲吻你
借酒劲吻你 2021-02-09 05:07

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

2条回答
  •  隐瞒了意图╮
    2021-02-09 05:57

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

提交回复
热议问题