Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

objective c - How to view contents of NSDictionary variable in Xcode debugger?

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

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

I was expecting it to show me each element of the dictionary (similar to an array variable).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

given:

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

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...