Here is the app window for my NSUndoManager demo. It is a document-based application b/c we get the NSUndoManager for free that way, and when I tried getting an instance of it directly (no-document), that didn't work. In my version of the Person class, each new person object has a number and a different expectedRaise. It's all standard.
class Person(NSObject): |
The buttons are wired to actions as usual. The TextField is bound to an ivar. The ivar "employees" holds the array of person objects. Here is the first part of the document class:
|
I won't show the standard document methods, but here is my implementation of add_ and remove_, based on Hillegass. "Undo" and "Redo" work correctly. And if we add two persons and then "Undo", the text field updates properly. If we do remove with the button, the text field also updates. But if we then do "Undo delete", the text field does not update. We can see that it has a new value if we press "show". I'm not sure why there is no update.
@objc.IBAction |
P.S. According to cocoadev, for a non-document app, we just need to get the undoManager from the window. It works! I set an outlet in the class and do:
undo = self.myWindow.undoManager() |