如何在Xcode调试器中查看NSDictionary变量的内容? [英] How to view contents of NSDictionary variable in Xcode debugger?

查看:466
本文介绍了如何在Xcode调试器中查看NSDictionary变量的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过Xcode调试器查看NSDictionary变量的键/值对?以下是在变量窗口中完全展开后的信息范围:

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).

推荐答案

在gdb窗口中,您可以使用 po

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

给定:

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;
}

当然这些是 NSString 对象打印得很好。 YMMV与其他复杂对象。

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

这篇关于如何在Xcode调试器中查看NSDictionary变量的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆