문제

I've got an edit view controller which I'm using an NSUndoManager for which is the one set for my persistence store (core data project).

One of the features of my app is synchronisation with an external server. What I want to know is, if I am editing something in my view, and at the same time the app is syncing itself with the server, if I change my mind and decide to undo any changes in my current edit, would it also undo all of the changes made during the sync if they were made whilst the undo grouping had started, or would it only undo changes I'd made myself?

도움이 되었습니까?

해결책

Depends on your implementation. Normally, the undo manager open an undo group for your event and encapsulates the changes, see groupsByEvent. If you use a secondary managed object context for your background synchronization and merge the context back in to the main context you have to ensure that you disabled the undo registration, see disableUndoRegistration.

Edit: Here is a little code snippet with that you can synchronize in a separate context without creating undo actions

// create a child context with no undo manager
NSManagedObjectContext *context = [NSManagedObjectContext contextWithParent:self.managedObjectContext];
context.undoManager = nil;

[... do your synchronization with the child context...]

// merge into main context without generating undo actions
[undoManager disableUndoRegistration];
[context save:&error];
[managedObjectContext processPendingChanges];
[undoManager enableUndoRegistration];

// to prevent undo action beyond the synchronization to remove all undo actions
[undoManager removeAllActions];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top