I work with CoreData on OSX (but I guess the problem is the same for iOS).

I would like to disable the undo management for the creation/deletion of NSManagedObjects. But, if possible, I would to keep the undo management for the attributes (like NSStrings, etc.) of my entities.

How can I do that?

If possible, I would like a global solution, such as subclass MyManagedObjectof NSManagedObject with overwritten methods (awakeFromInsert, prepareForDeletion).

有帮助吗?

解决方案 2

You can decide a associate no NSUndoManager to a NSManagedObjectContext :

    [self.managedObjectContext setUndoManager:nil] ;

其他提示

NSUndoManager has disableUndoRegistration and enableUndoRegistration methods to allow this. You need to intercept the operations that you don't want to be undoable and disable/enable the undo manager as appropriate. Note that calls to enable and disable must balance (don't call one without also calling (or having called) the other. It is also your responsibility to ensure that undoing any operation doesn't result in invalid state (this is the purpose of beginUndoGrouping).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top