Question

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).

Était-ce utile?

La solution 2

You can decide a associate no NSUndoManager to a NSManagedObjectContext :

    [self.managedObjectContext setUndoManager:nil] ;

Autres conseils

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).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top