I'm learning about undo, and I'd like a way to peek into the undo objects (NSInvocation
s) in the undoManager
so I can see what's going on. I couldn't see anything like this in the docs, but maybe someone knows a way.
Thanks.
I'm learning about undo, and I'd like a way to peek into the undo objects (NSInvocation
s) in the undoManager
so I can see what's going on. I couldn't see anything like this in the docs, but maybe someone knows a way.
Thanks.
Are you using Core Data? Core Data provides automatic undo/redo support. Otherwise, the NSUndoManager
will have an empty stack.
I suppose my question to you would be, why do you want to look at the stack? In practice, there's really no reason you should have to look at the undo manager's stack. If you're looking for advice on how to create undo actions and push them on the stack, here's a pretty good overview on how to do that. Apple's documentation on the subject is also quite good. I'm especially fond of the invocation-based method.
You can use
class-dump -C NSUndo /System/Library/Frameworks/Foundation.framework/Foundation
to find out about the inner structure of the undo related classes. You will find that the NSUndoManager has two instance variables named _undoStack and _redoStack. It's pretty obvious how it's structured, so you can write a little method printing the stack. I found that quite handy for debugging undo related problems.