Created
December 8, 2015 16:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) | |
{ | |
} |
Just the undo stack:
@try
{
NSUndoManager* undoManager = [self undoManager];
id undostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], NEVER_TRANSLATE("_undoStack")));
NSLog(@"%@",[NSString stringWithFormat:@"(%lu entries) %@", (unsigned long)[undostack count], [undostack description]]);
}
@catch (NSException* e)
{
}
Don't forget to #import <objc/runtime.h>
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
Note that now with our localization checkers, you need to prefix every string (yes even the C string) w/
NEVER_TRANSLATE()