MagicalRecord — saveinBackground not persisting data?

随声附和 提交于 2019-12-23 04:49:15

问题


I'm having trouble understanding the difference betweeen [[NSManagedObjectContext defaultContext] save] and [[NSManagedObjectContext defaultContext] saveInBackground].

When I use the save functionality, it works just fine but saveInBackground never persists the data. In short, this is the difference:

// Save in background.. DOES NOT WORK
    [[NSManagedObjectContext defaultContext] saveInBackgroundErrorHandler:^(NSError *error){
        NSLog(@"FAILED TO SAVE!! Task: %@", task);
    }completion:^(void){
        NSLog(@"PERSISTED NEW TASK: %@", task);
    }];

    // Save in main thread.. WORKS
    [[NSManagedObjectContext defaultContext] save];

Everytime saveInBackground runs, I see the "PERSISTED NEW TASK" log entry. However, when I restart the app, the data isn't there. When I use save, I restart the app and the data is there. What am I missing?


回答1:


Had to call [context saveNestedContexts]



来源:https://stackoverflow.com/questions/12410213/magicalrecord-saveinbackground-not-persisting-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!