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"]);
Share:
15,237

Related videos on Youtube

patrick
Author by

patrick

Updated on June 06, 2022

Comments

  • patrick
    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
    Ryan Poolos almost 12 years
    I 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.