views:

122

answers:

2

I'm learning about undo, and I'd like a way to peek into the undo objects (NSInvocations) 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.

+1  A: 

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.

Alex
I'm going through "Cocoa Programming for Mac OS X" which has a chapter on using undo. It's not using Core Data (yet).The reason I want to look at the stack is just to know how things are working so I can understand it better. I want to check that what's actually going on matches what I think is going on.
nevan
+4  A: 

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.

nschmidt
Thanks for the answer. For anyone (like me) who is wondering what class-dump is, I found it here: http://www.codethecode.com/projects/class-dump/
nevan