Q:

iPhone Core Data: Property Persistance During Undo

I've got a data model built in core data for the iPhone. I also have an NSUndoManager working for that model. The problem is that I have certain properties on an entity that i don't want affected back during an undo and other properties that I do want rolled back. Is this possible without drastically changing things. If so what is the best way to go about doing it.

A:

After a little reading...
The NSUndoManager methods:
- (void)disableUndoRegistration
- (void)enableUndoRegistration

will work provided that the NSManagedObjectContext method
- (void)processPendingChanges

is called directly after.
For example you could add the following method on a managed object to set weather or not a change to a property should be added to the undo stack:
- (void)setColor:(UIColor *)aColor undo:(BOOL)shouldUndo{
    if (shouldUndo)
        [self setColor:aColor];
    else{
        NSManagedObjectContext *moc = self.managedObjectContext;

        [moc processPendingChanges];                  //Disable undo
        [moc.undoManager disableUndoRegistration];

        [self setColor:aColor];                       //Preform change

        [moc processPendingChanges];                  //Enable undo
        [moc.undoManager enableUndoRegistration];
    }
}

Note, if you have a bunch of changes that you don't want added to the undo stack, this might not be the most efficient way to do it.

