问题描述
我一直在寻找与此相关的帖子,但我不完全理解...之间的区别是什么
I was looking for posts regarding to this, but I don't fully understand... What is the difference between:
[context reset];
和:
for (NSManagedObjectID *objId in objectIds) {
[context deleteObject:[context objectWithID:objId]];
}
还是等价的?
谢谢
推荐答案
使用 reset
放置托管对象上下文返回到您最初创建它时的状态-在执行任何提取,创建任何新对象等之前。如果内存中有任何从此上下文中提取的托管对象,则这些对象现在无法使用。使用重置
不会影响持久性存储文件。之后所有实例仍然存在,只是它们不在内存中。可以再次获取它们。
Using reset
puts the managed object context back to the state it was in when you first created it-- before you had performed any fetches, created any new objects, etc. If you have any managed objects in memory that were fetched from this context, they're now unusable. Using reset
does not affect the persistent store file. All instances still exist afterward, they're just not in memory. They can be fetched again.
使用 deleteObject
从持久性存储中删除对象。它不再存在。由于它不存在,因此无法再获取。
Using deleteObject
removes the object from the persistent store. It does not exist any more. It can't be fetched anymore because it doesn't exist.
这篇关于清除核心数据中的上下文:重置还是删除已注册的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!