NSObject 描述和 debugDescription
我已经看到出于调试目的提到了描述和调试描述,但还没有看到关于何时使用哪个以及在什么条件下它们可能会产生不同结果的精确解释。
NSObject 的文档也没有关于 debugDescription 的任何内容。问题:什么时候使用哪个,在什么条件下,它们的输出应该/会不同?
I have seen mentioning of description and debugDescription for debugging purposes, but have yet seen precise explanations of when to use which and under what conditions they may produce different results.
NSObject's documentation also doesn't have anything on debugDescription. Question: When to use which, and under what condition, should/would their output be different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
技术说明 TN2124
如果您实现了
debugDescription
,则在 GDB 中打印该对象将显示其结果。知道 UI 中使用了description
(我知道绑定可以做到这一点),您可能希望使用它来打印一些用户不需要看到的附加信息。Technical Note TN2124
If you have
debugDescription
implemented, printing the object in GDB will display its result. Knowing thatdescription
is used in UI (I know bindings do that), you may want to use this to print some additional information that user doesn't need to see.对已经讲过的内容进行补充。
如果您想在 lldb 中使用
po
时改进输出,您可以重写debugDescription
方法。请记住,打印 self(对象本身)将调用描述方法。如果由于某种原因
不适合您,也可以覆盖该方法。所以我在这里要强调的是,打印 self 将调用
description
方法,而po
调用debugDescription
,默认情况下调用description。有了这个,您就可以区分该调用的结果。One addition to what have already been told.
If you want to improve the output while working with
po
in lldb you can override thedebugDescription
method. Just keep in mind that printing self (the object itself) will call description method. If for some reason<ClassName: objectAddress>
is not good for you also override that method.So my point here was to highlight that printing self will call
description
method, whereaspo
callsdebugDescription
which by default calls description. Giving this you can differentiate the results of that calls.