I’ve recently noticed this strange thing about undo mechanism in Core Data and it’s bothering me ever since.
A quote from NSManagedObjectContext documentation for -undo method:
Sends an undo message to the receiver’s undo manager, asking it to reverse the latest uncommitted changes applied to objects in the object graph.
To reverse the latest uncommitted changes, sounds simple, right?
However, it’s not what is actually happening! Even if I save the context with changes on my managed object, the following -undo call will still successfully reverse the changes. Isn’t it against the thing stated in the docs?
Perhaps I’m doing something wrong? I can post my little testing code if needed. I’m really confused.
You should be confused. The Core Data documentation is a hot mess. They use a lot of words like “uncommitted” in arguably inappropriate ways. They seem to mean objects whose properties
isFaultedis equal to NO when they say “uncommitted”.The Core Data Programming guide goes into more detail:
The wording/vocabulary in the documentation is not clear or consistent. I believe the intended usage is that the you should call
removeAllActionson the context’sundoManagerproperty when appropriate for your application to avoid unlimited memory growth.