开发者

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

// 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜