I have an application that loads core data, then calls the XML Web Service to get updated data. I basically want my app, rather than to erase all the data and load everything (including new) to persist, I want it to add only the new stuff onto the existing stack (without duplication).
What’s the general consensus strategy for something like this?
I fetch an
NSSet*of all persisted objects and then perform an intersection operation on that set ofNSManagedObjectinstances with a new managed object, which is populated with the data from an individual XML element and its contents.If there is something left from that intersection, that means I have that element already in my data store. So I update the existing, already-persisted managed object’s properties with data from the XML element and save, discarding the new managed object.
If I have an empty set, the newly created managed object gets saved into the data store directly.
I don’t have a hash value available to compare between the persisted data and the XML data, so this works reasonably well.