The documentation says;
NSUpdatedObjectsKey
Key for the set of objects that were updated.
NSRefreshedObjectsKey
Key for the set of objects that were refreshed but were not dirtied in the scope of this context.
What does this actually mean. I just want to know what has changed, so do I need to watch both these keys?
NSUpdatedObjectsKey
means that a property of the object has changed. However if you set an property to the same values that was already there then it will also appear as NSUpdatedObjectsKey
even if nothing really changed. (ie issue.issueId = issue.issueId
will cause the object to be "changed").
NSRefreshedObjectsKey
means that the object was refetched from the store. If you are using more than one context at the same time then the object may have changed when you weren't looking. So calling refreshObject:mergeChanges:
on the context for those objects will cause them to be refetched from the store. This does not mean that they have change - but they may have.
In regards to using them, I am not sure why you would need either. Since NSPersistentContainer
, I haven't had any reason to use NSManagedObjectContextDidSaveNotification
at all, as NSPersistentContainer
manages all of the context merging and updates for me. When I did manage my own core data stack I mostly just passed along the entire notification to mergeChangesFromContextDidSaveNotification:
. I never called refreshObject:mergeChanges:
as I had other ways of making sure that the contexts remained in sync, so I never had any RefreshedObjects.
I'm not sure if answered your question, I hope that helps.
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