Will NSUndoManager undo changes happening in the background?

纵然是瞬间 提交于 2019-12-06 03:37:53

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!