Hello what's the difference between
[self.context refreshObject:site mergeChanges:YES];
and
[self.context save:nil];
Sometimes I use them both, sometimes I use only save
. It works in both cases.
-save:
saves the changes you've made to any managed object in the context. This means they get flushed to the persistent store coordinator, which then writes them to the persistent store, which writes them to disk (assuming a disk-backed store).
On the other hand, -refreshObject:mergeChanges:
does something quite different. It reads the current state of the object from the persistent store coordinator (which reads from the persistent store, and so on). Passing YES
for mergeChanges
means to keep any local modifications to the object intact and only update the fields that weren't changed. This is pretty much the opposite of -save:
.
As a trivial thought experiment, if you run -save:
and then terminate your app, on next launch your modified data will still be available. If you run -refreshObject:mergeChanges:
and then terminate your app, any of your local changes will be lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With