在 Xcode 调试器中检查数组的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10337468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:06:34  来源:igfitidea点击:

Inspecting the contents of an array in the Xcode debugger

objective-cxcodedebugging

提问by Hippocrates

Let's say I create an array:

假设我创建了一个数组:

NSArray *newArray = [NSArray arrayWithObjects:@"foo", @"bar", @"sdfsf", nil];

In Xcode, when I stop at a breakpoint and inspect newArrayI see that it says "3 Objects", yet when I click the disclosure triangle all I see is one NSObjectand there seems to be no way to see what that array contains.

在 Xcode 中,当我停在断点处并检查时,newArray我看到它显示“3 个对象”,但是当我单击显示三角形时,我看到的只有一个NSObject,似乎无法查看该数组包含的内容。

In practice I am working with an array of custom objects and it is a royal pain to see the nesting or inspect the properties of them.

在实践中,我正在处理一系列自定义对象,看到嵌套或检查它们的属性是一种极大的痛苦。

Can anyone provide some insight on a better way to use this?

任何人都可以提供一些有关使用它的更好方法的见解吗?

回答by Paul.s

If it is in scope you can just type

如果它在范围内,您只需键入

po newArray 

into the debugger and it will print the description.

进入调试器,它将打印描述。

Or if you prefer clicking things then just right click the object in the left panel pof the console and then click "Print Description of ..."

或者,如果您更喜欢单击事物,则只需右键单击控制台左侧面板中的对象,然后单击“打印...的描述”

回答by steveb

i'm a fan of NSLog. you should be too :)

我是 NSLog 的粉丝。你也应该是:)

NSLog(@"contents of newArray: %@", newArray);