[ACCEPTED]-How to view contents of NSDictionary variable in Xcode debugger?-debugging

Accepted answer
Score: 140

In the gdb window you can use po to inspect 5 the object.

given:

NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"foo" forKey:@"bar"];
[dict setObject:@"fiz" forKey:@"buz"];

setting a breakpoint after 4 the objects are added you can inspect what 3 is in the dictionary

(gdb) po dict
{
  bar = foo;
  buz = fiz;
}

Of course these are 2 NSString objects that print nicely. YMMV with other 1 complex objects.

Score: 30

You can right-click any object (ObjC or 13 Core Foundation) variable and select “Print 12 Description to Console” (also in Run->Variables 11 View). This prints the result the obejct’s 10 -debugDescription method, which by default calls -description. Unfortunately, NSDictionary overrides 9 this to produce a bunch of internal data 8 the you generally don’t care about, so in 7 this specific case craigb’s solution is 6 better.

The displayed keys and values also 5 use -description, so if you want useful information 4 about your objects in collections and elsewhere, overriding 3 -description is a must. I generally implement it along 2 these lines, to match the format of the 1 default NSObject implementation:

-(NSString *) description
{
    return [NSString stringWithFormat:@"<%@ %p>{foo: %@}", [self class], self, [self foo]];
}
Score: 6

You can use CFShow()

NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"foo" forKey:@"bar"];
[dict setObject:@"fiz" forKey:@"buz"];
CFShow(dict);

In output you will see

{
  bar = foo;
  buz = fiz;
}

0

Score: 3

XCode 4.6 has added the following functionality 3 which may be helpful to you

The elements of NSArray and NSDictionary objects can now be inspected in the Xcode debugger

Now you can inspect 2 these object types without having to print 1 the entire object in the console. Enjoy!

Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_6.html

Score: 1

Click on your dict, then click on the little 1 "i" icon, it should do the job :-) Xcode5, view the value of a dict

Score: 1

If you would like to print these in a breakpoint 7 action in modern XCode (yes, I am 10 years 6 after the original post!) use the following 5 breakpoint expression in a "Log Message" action:

@myDictionary.description@

Below 4 is a screenshot of my breakpoint action 3 where the variable event is an NSString 2 and the variable contextData is the NSDictionary 1 that I am logging the contents of: :

Score: 0

You can also use NSLog.

Also you can go in Debug 3 area or xcode, then find out All Variables, Registers, Globals and Statics then select 2 your variable. Right click on it. Then select 1 Print description of "...."

Hope it helps!

More Related questions