NSObject描述和debugDescription [英] NSObject description and debugDescription

查看:82
本文介绍了NSObject描述和debugDescription的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到出于调试目的而提到了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?

推荐答案

技术说明TN2124

注意:print-object实际上调用指定对象的debugDescription方法. NSObject通过调用description方法来实现此方法.因此,默认情况下,对象的调试描述与其描述相同.但是,如果您想将它们解耦,则可以覆盖debugDescription;否则,请参见.许多可可对象都这样做.

Note: print-object actually calls the debugDescription method of the specified object. NSObject implements this method by calling through to the description method. Thus, by default, an object's debug description is the same as its description. However, you can override debugDescription if you want to decouple these; many Cocoa objects do this.

如果已实现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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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