NSPrivateQueueConcurrencyType Not saving properly

后端 未结 1 960
谎友^
谎友^ 2020-12-01 20:22

The following method gets called in order to populate my Core-Data after AFNetworking fetches information from my app server.

The informati

相关标签:
1条回答
  • 2020-12-01 21:08

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