我应该在保存之前检查“[managementObjectContext hasChanges]”吗?
// Save changes if any.
NSError *error;
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
// TODO: handle this error better.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
// Save changes if any.
NSError *error;
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
// TODO: handle this error better.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这要看情况。如果您确定已对
managedObjectContext
进行了更改,则无需检查。但是,如果有任何可能尚未进行更改,那么您应该在保存之前进行检查。查看CoreDataBooks Xcode 示例应用程序的应用程序委托 获取这两种情况的示例。
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.