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.
+1
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.
Ben
2009-12-15 18:57:00
Generally, I've only needed the second -processPendingChanges when disabling undo registration.
Brad Larson
2009-12-16 16:06:18