Objective-C: looking inside NSDictionary
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?)
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?)
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]](http://upshot.fsdev.net/upshot_printToConsole.png)
You can also use various debugger commands in the console, which behaves using the current context for the breakpoint:
From this context, you can also use more advanced things, even call methods:
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.
HTH.
![[Image: upshot_printToConsole.png]](http://upshot.fsdev.net/upshot_printToConsole.png)
Code:
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 = "*******"}
}
(gdb)You can also use various debugger commands in the console, which behaves using the current context for the breakpoint:
Code:
(gdb) po info
{
password = *******;
username = *******;
}From this context, you can also use more advanced things, even call methods:
Code:
(gdb) po [info allKeys]
<__NSArrayI 0x588f090>(
username,
password
)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.
HTH.
Brilliant!! Those tricks work perfectly. And yes, I was mis-typing a key.

