Pergunta

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

Foi útil?

Solução 2

You can decide a associate no NSUndoManager to a NSManagedObjectContext :

    [self.managedObjectContext setUndoManager:nil] ;

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top