I agree with Ben that this seems somewhat odd to do, but that said:

NSManagedObjectContext coalesces changes for registering with the undo manager, but NSUndoManager also performs its own grouping. - processPendingChanges just provides a means for forcing the MOC to register its changes when you want. You still need to close off the undo managers grouping to match. So do something like ths:

[MOC processPendingChanges];

usnigned undoGrouping = 0;
while ([[MOC undoManager] groupingLevel] > 0)
{
        [[MOC undoManager] closeUndoGrouping];
        undoGrouping++;
}

while ([[MOC undoManager] groupingLevel] < undoGrouping)
{
        [[MOC undoManager] beginUndoGrouping];
}

On 2 Oct 2008, at 22:16, Peter Sagerson wrote:

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/cocoadev%40mikeabdullah.net

This email sent to [EMAIL PROTECTED]

_______________________________________________

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