How to print out a property's contents using Xcode debugger?

这一生的挚爱 提交于 2019-11-28 09:57:57

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:

Try with following expression in debug area to print object,

p self.view.bounds.size.width

or use,

po self.view

p - Print is only uses to print normal/simple values while, po - Print Object works same as NSLog to print value of an object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!