Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 908
AppsDev Avatar asked Aug 25 '15 09:08

AppsDev


1 Answers

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.

like image 134
Tom Harrington Avatar answered Nov 16 '22 00:11

Tom Harrington