简体   繁体   English

Xcode中的调试属性

[英]Debugging properties in Xcode

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.值得注意的是 UIView class 的“标签”属性。现在我设置了这个属性,如果我NSLog它,或者根据标签的值设置控制语句,我可以看到我设置的值在那里,并且被作为预期的。

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.但是,如果我 hover 将鼠标悬停在 .tag 上以查看那里有哪个标签值,我从 Xcode 中什么也得不到。没有弹出窗口显示该值。 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).然后我将 go 转到自动/本地/所有 window 并尝试“添加表达式...”(似乎这是设置传统“监视”变量的唯一方法,如果有其他方法,请告诉我)。 Anyhow so I put my object.tag into the "watch" window and it's blank.无论如何,我将我的 object.tag 放入“手表”window 中,它是空白的。 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).当然,如果我 hover 将鼠标悬停在“object.tag”的“object”部分上,那么我会弹出带有显示三角形的 object,然后我展开它,然后我 go 寻找“_tag”(看起来是底层实例变量)。

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?这与 Xcode dev 中的属性有关吗?

I'm running Xcode 4.3.2我正在运行 Xcode 4.3.2

The tag property, as any other Objective-C property, is a syntactic sugar.与任何其他 Objective-C 属性一样, tag属性是语法糖。 In fact, properties are implemented as accessor methods, which, in turn, are translated to objc_msgSend() function calls.事实上,属性被实现为访问器方法,而访问器方法又被转换为objc_msgSend() function 调用。 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.另一方面,获取 Objective-C 属性的值需要在进程上下文中执行代码。 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.考虑执行访问器方法更改对象内部 state 的情况。例如,调用-[UIViewController view] (访问其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.也可能调用委托方法等。在这种情况下,将鼠标悬停在 IDE 中的属性上会改变进程的执行 state,从而使调试本身成为一个笑话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM