如何使用Xcode调试器打印出一个属性的内容? [英] How to print out a property's contents using Xcode debugger?
问题描述
我正在编写一个iOS应用程序,我需要使用内置的Xcode调试器的帮助。假设我有一个名为 HomeViewController
的对象,它具有三个属性
@property (非原子)BOOL完成;
@property(nonatomic,strong)NSArray * myArray;
@property(nonatomic,strong)NSString * myName;
@synthesize finished = _finished,myArray = _myArray,myName = _myName;
假设我在这个类中有一个断点。我如何查看这些属性的内容?我尝试了诸如 po myName
, print myName
和 print [self myName]
但我无法弄清楚如何做到这一点。我试过使用LLDB,但我一直得到这个人遇到的同样的错误(
一旦您放置了断点,运行并且程序在断点停止,将光标悬停在变量/您希望看到的价值如下:
NSLog(@%@,yourLabel.text); 到查看该标签/其他对象类型的内容。
另一个选项是在控制台中运行GDB,如下所示:
gdb
附上<您的进程名称>
然后使用 po
对象)命令来查看像这样的变量的值:
po变量名称
要查看原始类型的值( int
, float
, long
, double
, char
等等),您可以在控制台中运行GDB时使用 print
命令,如下所示:
打印yourPrimitiveVariable
希望这有助于您!
编辑:
使用 po
命令,可以打印出一个同时使用属性名称( self.myProperty
)或伊娃名称(可能 _myProperty
)的对象。我在这里证明这一点:
I'm writing an iOS app and I need help using the built-in Xcode debugger. Suppose I have an object called HomeViewController
that has three properties
@property (nonatomic) BOOL finished;
@property (nonatomic, strong) NSArray *myArray;
@property (nonatomic, strong) NSString *myName;
@synthesize finished = _finished, myArray = _myArray, myName = _myName;
Suppose I have a breakpoint in this class. How would I view the contents of these properties? I've tried things such as po myName
, print myName
and print [self myName]
but I can't figure out how to do this. I've tried using LLDB but I keep getting the same error that this person encountered (lldb fails to print variable values with "error: reference to 'id' is ambiguous") . The accepted answer to this question was, LLDB is broken and that I should just use GDB; however, I refuse to accept that something so fundamental is broken.
Nevertheless, I've also tried using GDB with similar commands as above; however, I can't get GDB to work either. Help please
Once you place a breakpoint, run, and the program stops at the breakpoint, hover your cursor over the variable/value you want to see like this:
You could also place an NSLog(@"%@", yourLabel.text);
to view the contents of that label/other object type.
One other option is to run GDB in the console like this:
gdb
attach <your process name>
And then use the po
(print-object) command to view the value of a variable like this:
po variableName
To view the value of primitive types (int
, float
, long
, double
, char
, etc.), you can just use the print
command while running GDB in the console like this:
print yourPrimitiveVariable
Hope this helps!
EDIT:
With the po
command, you can print out the value of an object using both the property name (self.myProperty
) or the ivar name (possibly _myProperty
). I demonstrate this here:
这篇关于如何使用Xcode调试器打印出一个属性的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!