Core Data: Error when deleting/adding objects

后端 未结 1 1868
野趣味
野趣味 2021-01-31 12:39

Sometimes my app crashes when I want to update my Core Data file by downloading and parsing a json file. I get the following error:

CoreData: error: Serio

相关标签:
1条回答
  • 2021-01-31 13:21

    You shouldn't be accessing your managed object context on serialQueue. Take a look at the Concurrency section of the NSManagedObjectContext documentation.

    If in your code your context is using NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType concurrency type, you can use one of the block-based methods to ensure you're on the right queue:

    //asyncrhonous
    [self.managedObjectContext performBlock:^{
        //do stuff with the context
    }];
    
    //syncrhonous
    [self.managedObjectContext performBlockAndWait:^{
        //do stuff with the context
    }];
    
    0 讨论(0)
提交回复
热议问题