gpt4 book ai didi

objective-c - NSManagedObjectContext 重置和回滚有什么区别?

转载 作者:太空狗 更新时间:2023-10-30 03:13:21 24 4
gpt4 key购买 nike

文档说:

- (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.

似乎在我对我的上下文做了一些更改之后,调用这两个方法将做完全相同的事情:丢弃更改并将更新的对象恢复到它们最后提交的值。那么 -reset 到底做了什么?

最佳答案

关键部分在引用中

All the receiver's managed objects are “forgotten”.

- (void)reset; 将为您提供一个干净的 NSManagedObjectContext,其中没有任何对象,并且文档说明了任何 NSManagedObject你身边的东西应该被丢弃,因为它们不再有效。

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

关于objective-c - NSManagedObjectContext 重置和回滚有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8319926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com