Core Data undo grouping
Core Data undo grouping
- Subject: Core Data undo grouping
- From: Peter Sagerson <email@hidden>
- Date: Thu, 2 Oct 2008 14:16:39 -0700
I'm using CoreData for some internal state management that sometimes
requires an undo boundary in a specific place. In other words, I need
something along these lines to work:
NSManagedObject *object = [self getObjectFromSomewhere];
NSManagedObjectContext *context = [object managedObjectContext];
[object setValue:@"1" forKey:@"attr"];
[self forceUndoBoundaryInContext:context];
[object setValue:@"2" forKey:@"attr"];
[context undo];
STAssertEqualObjects([object valueForKey:@"attr"], @"1", @"");
Based on the documentation, it seems clear that all I have to do to
accomplish this is call processPendingChanges:
- (void)forceUndoBoundaryInContext:(NSManagedObjectContext *)context
{
[context processPendingChanges];
}
But this does not work. I installed notification handlers for
NSUndoManagerDidOpenUndoGroupNotification and
NSUndoManagerWillCloseUndoGroupNotification and I can see that the
group is not closed until I call undo. As a workaround, I've found
that I can fiddle with the context's undo manager directly:
- (void)forceUndoBoundaryInContext:(NSManagedObjectContext *)context
{
[context processPendingChanges];
[[context undoManager] endUndoGrouping];
[[context undoManager] beginUndoGrouping];
}
This works, but it seems kind of sneaky and underhanded and I'm not
entirely comfortable with it. Is there a better way to do this? Does
anyone else find this behavior inconsistent with the documentation for
processPendingChanges?
Thanks
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden