How to view contents of NSDictionary variable in Xcode debugger?

Is there a way to view the key / value pairs of an NSDictionary variable through the Xcode debugger? Here is the amount of information when it is fully expanded in the variable window:

Variable Value Summary jsonDict 0x45c540 4 key/value pairs NSObject {...} isa 0xa06e0720 

I expected it to show me every element of the dictionary (similar to an array variable).

+82
debugging objective-c xcode cocoa
Sep 22 '08 at 1:45
source share
6 answers

In the gdb window, you can use po to test the object.

Given:

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

setting a breakpoint after adding objects, you can check what is in the dictionary

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

Of course, these are NSString objects that print well. YMMV with other complex objects.

+131
Sep 22 '08 at 1:51
source share

You can right-click any object variable (ObjC or Core Foundation) and select "Print Description to Console" (also in Run-> Variables View). This outputs the result to the obejcts -debugDescription method, which by default calls -description . Unfortunately, NSDictionary overrides this to create a bunch of internal data that you don't like at all, so in this particular case, craigbs solution is better.

Displayed keys and values ​​also use -description , so if you need useful information about your objects in collections and elsewhere, overriding -description is required. I usually implement it along these lines to fit the default implementation format of NSObject :

  - (NSString *) description
 {
     return [NSString stringWithFormat: @ "<% @% p> {foo:% @}", [self class], self, [self foo]];
 } 
+30
Sep 22 '08 at 9:55
source share

You can use CFShow ()

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

In the output you will see

 { bar = foo; buz = fiz; } 
+5
Jun 14 2018-12-12T00:
source share

Xcode 4.6 has added the following features that may be useful to you.

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

Now you can check these types of objects without printing the entire object in the console. Enjoy it!

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

+3
Apr 19 '13 at 22:06 on
source share

You can also use NSLog .

You can also go into the debug area or xcode, then find out All Variables, Registers, Globals and Statics , and then select your variable. Right click on it. Then select Print description of "...."

Hope this helps!

0
Dec 19 '12 at 13:56
source share

Click on your recorder, then click on the small β€œi” icon, it should complete the task :-) Xcode5, view the value of a dict

0
Nov 26 '13 at 4:48
source share



All Articles