How can I get the value / keys of NSDictionary objects in the debugger console?
15,237
Solution 1
The lldb command print expects that the value you wish to print is a non-object. The command you should be using to print objects is po.
When you tell lldb to print the value it looks for a method called allKeys that returns a non-object and fails. Try the following command instead...
po [[self dictionary] allKeys]
Solution 2
To print the description
of the object in GDB or LLDB you need to use print-object
or po
.
(lldb) po [self dictionary]
(lldb) po [[self dictionary] objectForKey:@"foobar"]
Solution 3
Why not just do
NSLog(@"dict: %@", dictionary);
or
NSLog(@"dict objectForKey:foobar = %@", [dictionary objectForKey:@"foobar"]);
Related videos on Youtube
Author by
patrick
Updated on June 06, 2022Comments
-
patrick about 2 years
I set a breakpoint...
if I do:
(lldb) print [self dictionary] (NSDictionary *) $5 = 0x0945c760 1 key/value pair
but if I do:
(lldb) print [[self dictionary] allKeys] error: no known method '-allKeys'; cast the message send to the method's return type error: 1 errors parsing expression
Even if I try to access the key that I know is in there..
(lldb) print [[self dictionary] objectForKey:@"foobar"] error: no known method '-objectForKey:'; cast the message send to the method's return type error: 1 errors parsing expression
What am I doing wrong?
-
Ryan Poolos almost 12 yearsI think he's trying to get the information from the console not source code. However it is the better way to do it in my opinion.