Master data - discard changes after saving context

I recently noticed this strange thing about the cancellation mechanism in Core Data, and it has been bothering me since then.

Quote from the NSManagedObjectContext documentation for the -undo method:

Sends a cancellation message to the receiver cancellation manager with a request to discard the last uncommitted changes applied to the objects in the object graph.

To undo the last uncommitted changes sounds easy, right?

However, this is not what is actually happening! Even if I save the context with the changes to the managed entity, the next call to -undo will still successfully -undo changes. Is this not against what is indicated in the documents?

Maybe I'm doing something wrong? If necessary, I can send my little test code. I'm really confused.

+6
source share
1 answer

You must be embarrassed. Master data documentation is a hot mess. They use many words, such as "uncommitted", in possibly inappropriate ways. They seem to mean objects whose properties isFaulted are NO when they say "uncommitted".

The master data programming guide is detailed below:

Change Management and Undo

The context retains strong references to managed objects that were waiting for a change (insert, delete, or update) until the context is sent a save :, reset, rollback or dealloc message, or cancel the corresponding number to cancel the change.

The undo manager associated with the context maintains strong references to any modified managed objects. By default, in OS X contexts canceled, the manager saves an unlimited stack of undo / redo. To limit the application’s memory, you need to make sure that you clear (using removeAllActions ) the context of the undo stack as and when appropriate . If you do not refer to the context cancellation manager, it is freed from the context.

The vocabulary / vocabulary in the documentation is not clear or consistent. I believe the intended use is that you should call removeAllActions on the undoManager context undoManager when appropriate for your application to avoid unlimited memory growth.

+3
source

All Articles