微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xcode 4 / gdb /如何简单地观察对象属性?

我在 Xcode 4中迷失了.看一个简单的变量是一场噩梦.我不知道如何“观察变量值”.在Xcode 3中更容易……

我有以下代码

if (labelEast.center.x > (east_oldPosition.x + 50) )
        NSLog(@"Time to switch to prevIoUs exercise !");
    else if (labelEast.center.x < (east_oldPosition.x - 50) )
        NSLog(@"Time to switch to next exercise !");

设置断点后,我只是想看看labelEast.center.x(labelEast是一个UILabel对象).由于我在Xcode 4菜单中找不到监视项目,因此我尝试使用gdb.我习惯用po(打印对象)打印变量/对象值.但是现在,我无法显示labelEast中心属性,因为它是从母类继承的.

(gdb) po labelEast.center
There is no member named center.

我不明白为什么gdb说这个,而代码工作正常并看到属性.

因此我有两个问题:

>如何在没有gdb的情况下以图形方式观看这样的属性(就像在Visual Studio中一样)?
>如何用gdb做同样的事情?

非常感谢,
弗朗茨

不幸的是,我尝试了但得到了这个:

po [labelSouth center]

Program received signal EXC_BAD_ACCESS,Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x1a000356 0x343c7d06 in
objc_msgSend_stret () The program being debugged was signaled while in
a function called from GDB. GDB remains in the frame where the signal
was received. To change this behavior use “set unwindonsignal on”
Evaluation of the expression containing the function (objc_msgSend)
will be abandoned.

当我尝试:

(gdb) print labelSouth.center
There is no member named center.

我真的怀疑UILabel没有中心物业.但我怎么能运行代码???

解决方法

我自己几次打这个东西只是为了记住“哦,没错,gdb不支持点符号所以我必须使用getter”.然后就做:

(gdb) po [myObject someProperty]

一切都与世界相处得很好.同时重读你的问题我发现你要求打印一个非对象,因此你必须给gdb一个你要打印的属性类型的提示

(gdb) p (CGRect)[myView frame]
(gdb) p (CGPoint)[myView center]

等等.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐