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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to