What is the difference between maintaining a managed entity context and refreshObject: mergeChanges:

Hi what's the difference between

[self.context refreshObject:site mergeChanges:YES]; 

and

  [self.context save:nil]; 

Sometimes I use both of them, sometimes I use only save . It works in both cases.

+4
source share
1 answer

-save: saves the changes you make to any managed entity in context. This means that they are dumped into the permanent storage coordinator, which then writes them to the permanent storage, which writes them to disk (provided they are stored on disk).

-refreshObject:mergeChanges: other hand does something completely different. It reads the current state of the object from the permanent storage coordinator (which is read from the permanent storage, etc.). Passing YES to mergeChanges means keeping any local changes to the object intact and updating only the fields that have not been changed. It is almost the opposite of -save:

Like a trivial thought experiment, if you run -save: and then terminate your application, the next time you run your changed data will still be available. If you run -refreshObject:mergeChanges: and then terminate your application, any of your local changes will be lost.

+8
source

All Articles