NSPrivateQueueConcurrencyType Not saving properly

£可爱£侵袭症+ 提交于 2019-11-27 09:21:50

You have to save the main context as well at some point, e.g. after saving the child context.

Saving the child context saves only to the main context, and saving the main context saves to the store file.

Like this (written on the phone, there will be syntax errors):

// ...
[childContext save:&error];
[mainContext performBlock:^{
    [mainContext save:&error];
}];

In Swift 2.0 that would be:

do {
    try childContext.save()
    mainContext.performBlock { 
        do {
            try mainContext.save()
        } catch let err as NSError {
            print("Could not save main context: \(err.localizedDescription)")
        }
    }
} catch let err as NSError {
    print("Could not save private context: \(err.localizedDescription)")
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!