I've got an elegant system set up using Core Data where any time a property of a model object is changed it is automatically reflected in its associated view using key-value observing but I have ran into a problem using undo.
The problem occurs when I have deleted a model object. The associated view is destroyed along with all the key-value observing when this occurs. The user suddenly decides that the deletion was a bad idea and issues an undo command restoring the model object. At this point the key-value observing has been destroyed and I can't seem to find a nice way to figure out which model object has been brought back from the dead and set everything up again.
The current solution I've thought of is registering for the NSUndoManagerDidUndoChangeNotification and then manually going through my Core Data model objects and seeing which ones do not have an associated view. I figure there must be a way to just know which particular object has been brought back though and thought this approach would be overkill.
I've also thought about creating an undo group where the removed view is re-added when the model object reappears but I would like to keep my undo manager related to the model only if that is possible.
I guess the solution I'm looking for is having the undo manager say, "Hey! Anybody who is interested listen up! I just did an undo and here is the Core Data model object that has been resurrected! Do with it what you will!" and then me setting up the view as if a new model object has been created.
Any ideas or guidance?