Question: 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?

Answer: 
The following method of [NSManagedObject](http://developer.apple.com/mac/library/documentation/cocoa/reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html#//apple_ref/occ/instm/NSManagedObject/awakeFromSnapshotEvents:) could be the the right point to setup observings again:

```
- (void)awakeFromSnapshotEvents:(NSSnapshotEventType)flags

```

It is sent to a NSManagedObject after undo/redo operations
> 
> 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.
> 
> 
> 

I'm not sure what you mean by that but a view should not be so directly tied to the model that the view object itself dies when the model deletes something. The controller should be handling that and should be able to reverse it. 

It sounds like you need to register the controller for one of the [undo manager notifications.](http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSUndoManager_Class/Reference/Reference.html#//apple_ref/doc/uid/20000211-CJBGADBA) That will at least let you know when an undo has been performed and then you can take appropriate action.