Re: Core data and disabling undo registration
Re: Core data and disabling undo registration
- Subject: Re: Core data and disabling undo registration
- From: Mike Abdullah <email@hidden>
- Date: Mon, 18 Jul 2011 10:19:08 +0100
On 18 Jul 2011, at 01:12, Gideon King wrote:
> Hi all, in the documentation "Using Managed Objects", it says that we should use:
>
> [moc processPendingChanges]; // flush operations for which you want undos
> [[moc undoManager] disableUndoRegistration];
> // make changes for which undo operations are not to be recorded
> [moc processPendingChanges]; // flush operations for which you do not want undos
> [[moc undoManager] enableUndoRegistration];
>
> When disabling undo registrations, but in the example code for both Adding a Department Object, and A Sheet for Creating a New Employee, it uses:
>
> [[managedObjectContext undoManager] disableUndoRegistration];
> // Do stuff
> [managedObjectContext processPendingChanges];
> [[managedObjectContext undoManager] enableUndoRegistration];
>
> (i.e. it only does a processPendingChanges once instead of twice)
>
> I was doing some performance tuning of my application and it appeared that the processPendingChanges is a moderately expensive operation, even when there are basically no pending changes, so I tried removing the first processPendingChanges as per the examples, and it still seems to be working correctly.
>
> Does anyone know of any reason why the first processPendingChanges would be necessary?
Yes, if some unprocessed changes had already been made to the context that you *do* want on the undo stack. Without a call to -processPendingChanges, those would only be processed while registration is disabled, which probably isn't the desired result.
_______________________________________________
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