Is there a way to view the undo stack?

cocoa, macos, objective-c, undo

Solution

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.

Problem

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.

Original source