I'm trying to use Persistent History Tracking to implement data synchronization with the server. The idea is that for every NSPersistentHistoryTransaction, I want to (eventually) make analogous REST requests to perform identical change on the server.
My code iterates through all the changes in the transaction. When the change is a DELETE, I can't figure out, how to tell what object type was deleted. As far as I can tell, the only thing I've got is the tombstone - which are some of the original object's fields (externalId in my case). While ID is an identifier, I also need to know what entity that ID belongs to.
The documentation for the whole Core Data feature is next to none :-/
The only solution I could come up with is to add a new field to each entity. The field name is entityType, type is String and the default value is whatever the entity is. And I set the "Preserve After Deletion" for this field.
This does solve the the problem. The drawback is that I store few extra bytes for every record I save.
If anyone can think of a better solution, I'd love to see it.
Have you tried getting the NSPersistentHistoryChange.changedObjectID.entity? (Maybe I’m missing something—I haven’t tried it—but it seems liek that should work.)
That seems to work. I'm new to Persistent History Tracking and I thought changedObjectID is just the ID which is irelevant after the object has been deleted.
Thanks a lot