App freeze on CoreData save

后端 未结 2 697
一个人的身影
一个人的身影 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:45

    So I now believe the problem was that I was sometimes writing an NSNumber with float value to an integer field. This caused the copy in memory to be different than the copy read from the database, and this caused the infinite merge loop. But if you restarted the app it worked fine because the value was simply an integer from then on.

    0 讨论(0)
  • 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];
    
    0 讨论(0)
提交回复
热议问题