Xcode 中的调试属性 [英] Debugging properties in Xcode

查看:24
本文介绍了Xcode 中的调试属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一些我正在使用的示例代码中使用的属性.值得注意的是标签"UIView 类的属性.现在我设置了这个属性,如果我 NSLog 它,或者根据 tag 的值设置控制语句,我可以看到我设置的值在那里,并且按预期执行.>

但是,如果我将鼠标悬停在 .tag 上以查看存在哪个标签值,我将一无所获.没有弹出显示值.然后我转到自动/本地/所有窗口并尝试添加表达式...".(似乎这是设置传统观察"变量的唯一方法,如果有其他方法,请告诉我).无论如何,我将 object.tag 放入watch"中窗口,它是空白的.没有价值.它不是零,它只是什么都没有,就好像它不存在一样.

当然,如果我将鼠标悬停在对象"上object.tag"的一部分然后我会弹出一个带有显示三角形的对象,我将其展开,然后我去寻找_tag";(这似乎是底层实例变量).

那么这有什么难的呢?为什么在调试期间不能通过简单地将鼠标悬停在标签属性上来查看它?这与 Xcode dev 中的属性有关吗?

我正在运行 Xcode 4.3.2

解决方案

tag 属性与任何其他 Objective-C 属性一样,是一种语法糖.事实上,属性被实现为访问器方法,而访问器方法又被转换为 objc_msgSend() 函数调用.这种机制与访问结构字段完全不同.

调试器基本上可以显示结构中的任何字段,因为它不需要任何特殊知识,也不会产生任何后果.只需要结构定义.另一方面,获取 Objective-C 属性的值需要在流程上下文中执行代码.您可以在调试器控制台中手动执行此操作,但调试器不会自动执行此操作.

我认为这在理论上仍然是可能的在个别情况下,但非常困难.考虑执行访问器方法更改对象内部状态的情况.例如,调用 -[UIViewController view](访问其 view 属性)会导致加载视图.也可能会调用委托方法等.在这种情况下,将鼠标悬停在 IDE 中的属性上会改变进程的执行状态,从而使调试本身成为一个笑话.

So I have a few properties that I'm using in some sample code I'm playing with. Notably the "tag" property of the UIView class. Now I set this property, and if I NSLog it, or setup control statements based on the value of tag, I can see that the value I set is there, and being acted upon as expected.

However, if I hover the mouse over the .tag to see which tag value is there, I get nothing at all from Xcode. No pop up showing the value. So then I go to the auto/local/all window and I try to "Add Expression..." (seems that's the only way to setup a traditional "watch" variable, if there is another way, please let me know). Anyhow so I put my object.tag into the "watch" window and it's blank. No value. It isn't zero it's just nothing, as if it didn't exist.

Of course if I hover the mouse over the "object" part of "object.tag" then I get a pop up for the object with the disclosure triangle, which I expand, then I go looking for "_tag" (which appears to be the underlying instance variable).

So what is so difficult about this? Why isn't the tag property viewable during debug by simply hovering over it? Is this something to do with properties in Xcode dev?

I'm running Xcode 4.3.2

解决方案

The tag property, as any other Objective-C property, is a syntactic sugar. In fact, properties are implemented as accessor methods, which, in turn, are translated to objc_msgSend() function calls. This machinery is nothing like accessing a struct field.

The debugger can show any field in a struct basically because it doesn't require any special knowledge and doesn't have any consequences. Only the struct definition is needed. Getting the value of an Objective-C property, on the other hand, requires executing code in the process context. You can do that manually in the debugger console, but the debugger just won't do this automatically.

I think this is still theoretically possible in isolated cases, but incredibly hard. Consider a case where executing an accessor method changes the object's internal state. For example, calling -[UIViewController view] (accessing its view property) results in loading the view. There may also be delegate methods called, etc. In such cases hovering the mouse over the property in IDE would alter the execution state of the process and thus make debugging itself a joke.

这篇关于Xcode 中的调试属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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