Objective-C: looking inside NSDictionary

Posts: 14
Joined: 2009.04
Post: #1
Hey all,

I've setup an NSMutableDictionary (named "availableStates") but I keep getting NIL when I try to retrieve an object using objectForKey.

So I stuck a break-point in the code and when I run/debug it, I look up in the "Variables" area and I can see that availableStates has 2 key/value pairs (which is correct). If I click the triangle to expand, it says "NSDictionary". If I click the triangle next to that, it says "NSObject". Expanding that triangle gives me "isa". Then I keep getting "isa" forever if I keep expanding the triangles.

So... how do I look inside the NSMutableDictionary to see what the key/value pairs actually are? (Or an NSMutableArray, or the non-mutable versions?)

Quote this message in a reply
Posts: 149
Joined: 2009.11
Post: #2
For whatever reason the data structure browser doesn't work for me when using method arguments. You can, however, print it to the debugger console by right-clicking on it in the debugger window:

[Image: upshot_printToConsole.png]

Printing description of info:
<CFBasicHash 0x5a51420 [0x17c93e0]>{type = immutable dict, count = 2,
entries =>
    0 : <CFString 0xcbae8 [0x17c93e0]>{contents = "username"} = <CFString 0x5a582f0 [0x17c93e0]>{contents = "*******"}
    2 : <CFString 0xcbba8 [0x17c93e0]>{contents = "password"} = <CFString 0x5a35de0 [0x17c93e0]>{contents = "*******"}

You can also use various debugger commands in the console, which behaves using the current context for the breakpoint:

(gdb) po info
    password = *******;
    username = *******;

From this context, you can also use more advanced things, even call methods:

(gdb) po [info allKeys]
<__NSArrayI 0x588f090>(

FWIW, your root problem is probably that you're mis-typing the key that you want. Using po [info allKeys] (replacing info with the name of your NS(Mutable)Dictionary, you should see the problem fairly quickly.


Everyone's favourite forum lurker!
Quote this message in a reply
Posts: 14
Joined: 2009.04
Post: #3
Brilliant!! Those tricks work perfectly. And yes, I was mis-typing a key. Smile
Quote this message in a reply
Post Reply