NSManagedObjectContext重置和回滚之间有什么区别? [英] what's the difference between NSManagedObjectContext reset and rollback?
问题描述
文件说明:
- (void)reset
$
讨论
所有接收者的管理对象都被忘记了。如果你使用这种方法,你应该确保你也丢弃对使用接收者获取的任何管理对象的引用,因为它们以后会失效。
- (void)rollback
从撤消堆栈中删除所有内容,丢弃所有插入和删除,
讨论
此方法不会从持久存储区重新获取数据,存储。
看来我对我的上下文做了一些改变后,调用这两个方法将做同样的事情:discard changes并将更新的对象恢复到其上次提交的值。那么 -reset
实际上是做什么的?
所有接收者的管理对象都被忘记。
- (void)reset;
会给你一个干净的 NSManagedObjectContext
它和文档状态任何 NSManagedObject
'你应该被丢弃,因为他们不再有效。
- (void)rollback
将只是将 NSManagedObject
恢复为它们的持久值
The documentation says:
- (void)reset
Returns the receiver to its base state.
Discussion
All the receiver's managed objects are "forgotten." If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver, since they will be invalid afterwards.
- (void)rollback
Removes everything from the undo stack, discards all insertions and deletions, and restores updated objects to their last committed values.
Discussion
This method does not refetch data from the persistent store or stores.
It seems that after I make some change to my context, calling these two method will do exactly the same thing: discard changes and restore updated objects to their last committed values. So what does -reset
actually do?
The key part is in the quote
All the receiver's managed objects are "forgotten".
- (void)reset;
will give you a clean NSManagedObjectContext
with no objects in it and as the docs state any NSManagedObject
's you have around should be discarded as they are no longer valid.
- (void)rollback
will just restore the NSManagedObject
's to their persisted values
这篇关于NSManagedObjectContext重置和回滚之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!