{
Items = {
Item = {
text = "item 1";
}
Item = {
text = "item 2";
}
Item = {
text = "item 3";
}
}
}
Above is an example of my NSDictionary. Keep it in mind for this next snippet.
NSDictionary *dict = {the afore mentioned dictionary is here}
int count = [[[dict objectForKey:@"Items"] allKeys] count]; // Breakpoint here
NSLog(@"%i", count); // Breakpoint here
In my breakpoints, I get the following values for count
- On breakpoint 1:
count = (int) 128037184(or some other random and big int) - On breakpoint 2:
count = (int) 5
I would have expected an int of 3 both times. What’s going on?
In the first case, you’re breaking before the line is executed, so
countwill have whatever random data happens to be in that spot on the stack. If you step over that instruction in the debugger, you’ll seecountchange to a more reasonable number.In the second case, I’m not sure why you have more keys than you expect, but the simple thing to do would be to just log the entire dictionary and see what’s there:
That’ll show you all the keys and values in the dictionary, which may explain the number you’re getting.