I have a method that creates a new NSMutableDictionary, sets some objects and then returns that dictionary with an autorelease like so:
NSMutableDictionary* parameters = [NSMutableDictionary new];
[parameters setObject:@"banana" forKey:@"fruit"];
[parameters setObject:@"potato" forKey:@"vegetable"];
[parameters setObject:@"water" forKey:@"drink"];
return [parameters autorelease];
Everything works but when I set a breakpoint before I return the parameters pointer, and want to see what’s inside with gdb by using print object it shows me the objects. But when I want to access the count it fails and tells me that it does not point to a valid object?
(gdb) po parameters
{
drink = water;
fruit = banana;
vegetable = potato;
}
(gdb) po [parameters count]
0x3 does not appear to point to a valid object.
What is going on?
You are using po with the dictionary count as argument. So GDB is actually trying to print an object located at memory address 3 (the count).
Your dictionary is fine.
If you want to print the count value, use p instead of po.