-
Notifications
You must be signed in to change notification settings - Fork 791
pkp: po alternative to lookup via valueForKeyPath: #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ce3dc97
5ccee16
72adcb4
bea8bee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ def lldbcommands(): | |
| FBPrintOnscreenTableViewCells(), | ||
| FBPrintInternals(), | ||
| FBPrintInstanceVariable(), | ||
| FBPrintKeyPath(), | ||
| ] | ||
|
|
||
| class FBPrintViewHierarchyCommand(fb.FBCommand): | ||
|
|
@@ -272,3 +273,28 @@ def run(self, arguments, options): | |
|
|
||
| printCommand = 'po' if ('@' in ivarTypeEncodingFirstChar) else 'p' | ||
| lldb.debugger.HandleCommand('{} (({} *)({}))->{}'.format(printCommand, objectClass, object, ivarName)) | ||
|
|
||
| class FBPrintKeyPath(fb.FBCommand): | ||
| def name(self): | ||
| return 'pkp' | ||
|
|
||
| def description(self): | ||
| return "Print out the value of [self valueForKeyPath:<>]." | ||
|
|
||
| def args(self): | ||
| return [ | ||
| fb.FBCommandArgument(arg='keypath', type='NSString *', help='The keypath to print'), | ||
| ] | ||
|
|
||
| def run(self, arguments, options): | ||
| keys = arguments[0].split('.') | ||
|
|
||
| if keys.count == 1: | ||
| print '"' + arguments[0] + '" is not a keypath =(' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about treating this case as equal to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an interesting idea, to add durable-ness, but I think it'd need a lot more checks than the presence of a '.' to be worth implementing. IE, [UIApplication sharedApplication].keyWindow would still blow up. I'd rather blow up in all slightly-wrong scenarios just keep clarity of intent.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment. Personally, while debugging, I'd rather make things as convenient as possible :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, looking at it again, I totally agree. |
||
| return | ||
|
|
||
| object = keys[0] | ||
| keys = keys[1:len(keys)] | ||
| keypath = ".".join(keys) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked the previous way, using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My python is terrible. Cleaned it up a tad. I also see the possibility of stepping through the key path in python and asking the object if it responds, and the stepping, or printing a good error message if it doesn't respond.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Don't worry, Chisel was written by objc developers :)
💵 Ooh! It would even allow typos correction if we queried inspected the selectors on an object and found the nearest match.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I added some basic stepping through the key path, but an object can return a value from I'm not sure if you use FuzzyAutocomplete, but that does perform a good deal of completion/typo fixes when using po (when it works). pkp does not get the auto-completion help like po does though. Any idea how that could be fixed?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for looking into it! It's probably diminishing returns to implement walking the key path. |
||
| printCommand = 'po [(NSObject *){} valueForKeyPath:@"{}"]'.format(object, keypath) | ||
| lldb.debugger.HandleCommand(printCommand) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
selfhere is misleading. To offer a possible wording: