SManagedObjectContext重置和回滚之间有什么区

SManagedObjectContext重置和回滚之间有什么区

本文介绍了NSManagedObjectContext重置和回滚之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件说明:






看来我对我的上下文做了一些改变后,调用这两个方法将做同样的事情:discard changes并将更新的对象恢复到其上次提交的值。那么 -reset 实际上是做什么的?

解决方案

- (void)reset; 会给你一个干净的 NSManagedObjectContext 它和文档状态任何 NSManagedObject '你应该被丢弃,因为他们不再有效。



- (void)rollback 将只是将 NSManagedObject 恢复为它们的持久值


The documentation says:


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

- (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重置和回滚之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:56