How can I get the value / keys of NSDictionary objects in the debugger console?
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]
error: no known method '-objectForKey:'; cast the message send to the method's return type
So, it tells you it can't deduce return type information merely from the name of the message send - and that's perfectly fine. And it even tells you how exactly you have to resolve that problem - you have to cast the message send to the method's return type.
Firing up Apple's docs, we find out that - [NSDictionary objectForKey:]
returns id
- the generic Objective-C object type. Casting to id (or even better, if you know what types of objects your dictionary holds, casting to that exact object type) does the trick:
(lldb) print (MyObject *)[(NSDictionary *)[self dictionary] objectForKey:@"foobar"]
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"]