问题描述
我已经看到出于调试目的而提到了description和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的文档在debugDescription上也没有任何内容.问题:什么时候使用,什么情况下,它们的输出应该/应该不同?
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?
推荐答案
如果已实现debugDescription
,则在GDB中打印对象将显示其结果.知道UI中使用了description
(我知道绑定就是这样做的),您可能希望使用它来打印一些用户不需要查看的其他信息.
If you have debugDescription
implemented, printing the object in GDB will display its result. Knowing that description
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.
这篇关于NSObject描述和debugDescription的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!