Clearing a context in Core Data: reset vs deleting registered objects?

我的梦境 提交于 2020-01-13 10:46:10

问题


I was looking for posts regarding to this, but I don't fully understand... What is the difference between:

[context reset];

and:

for (NSManagedObjectID *objId in objectIds) {
  [context deleteObject:[context objectWithID:objId]];
}

Or are they equivalent?

Thanks


回答1:


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.

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.



来源:https://stackoverflow.com/questions/32199920/clearing-a-context-in-core-data-reset-vs-deleting-registered-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!