App freeze on CoreData save

后端 未结 2 724
一个人的身影
一个人的身影 2021-01-02 09:00

I have an iPhone app that freezes sometimes when saving CoreData and then doesn\'t relaunch. I did have a second thread that uses the database, but I think I have followed t

2条回答
  •  误落风尘
    2021-01-02 09:50

    When using Core Data from multiple threads, make sure to lock your PSC before a save operation:

    [self.persistentStoreCoordinator lock];
    NSManagedObjectContext *context = //your context;
    [context save:&error];
    if (error) {
        // handle error
    }
    [self.persistentStoreCoordinator unlock];
    

提交回复
热议问题