Skip to content

Instantly share code, notes, and snippets.

@MattyAyOh
Created December 8, 2015 16:01
Show Gist options
  • Save MattyAyOh/71b640cf88cc4e059927 to your computer and use it in GitHub Desktop.
Save MattyAyOh/71b640cf88cc4e059927 to your computer and use it in GitHub Desktop.
Log out the undo and redo stack on an NSUndoManager using objc/runtime to access private ivars
@try
{
NSUndoManager* undoManager = [self undoManager];
id undostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], "_undoStack"));
id redostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], "_redoStack"));
NSLog(@"%@",[NSString stringWithFormat:@"(%lu entries) %@", (unsigned long)[undostack count], [undostack description]]);
NSLog(@"%@",[NSString stringWithFormat:@"(%lu entries) %@", (unsigned long)[redostack count], [redostack description]]);
}
@catch (NSException* e)
{
}
@MattyAyOh
Copy link
Author

For Swift:

    let undoManager = NSDocumentController.shared().currentDocument?.undoManager
    let undostack = object_getIvar(undoManager, class_getInstanceVariable(UndoManager.self, "_undoStack"));
    print(undostack.debugDescription)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment