gpt4 book ai didi

objective-c - NSObject 描述和 debugDescription

转载 作者:太空狗 更新时间:2023-10-30 03:08:50 25 4
gpt4 key购买 nike

我曾看到提到 description 和 debugDescription 用于调试目的,但还没有看到关于何时使用它们以及在什么条件下它们可能产生不同结果的精确解释。

NSObject 的文档也没有任何关于 debugDescription 的内容。问题:什么时候使用 which,在什么条件下,它们的输出应该/会不同吗?

最佳答案

Technical Note TN2124

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 中打印对象将显示其结果。知道 description 在 UI 中使用(我知道绑定(bind)会那样做),您可能想使用它来打印一些用户不需要看到的附加信息。

关于objective-c - NSObject 描述和 debugDescription,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com