开发者

Should I check if `[managedObjectContext hasChanges]` before saving?

开发者 https://www.devze.com 2023-02-18 09:08 出处:网络
// Save changes if any. NSError *error; if ([managedObjectContext hasChanges] && ![managedObjectContext开发者_C百科 save:&error]) {
// Save changes if any.
NSError *error;
if ([managedObjectContext hasChanges] && ![managedObjectContext开发者_C百科 save:&error]) {
    // TODO: handle this error better.
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}


That depends. If you're sure that changes have been made to the managedObjectContext, then there's no need to check. However, if there's any possibility that changes have not been made, then you should check before saving.

Check out the application delegate of the CoreDataBooks Xcode sample app for examples of both these scenarios.

0

精彩评论

暂无评论...
验证码 换一张
取 消