NSObject description and debugDescription

↘锁芯ラ 提交于 2019-11-28 20:10:56

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.

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.

One addition to what have already been told.

If you want to improve the output while working with po in lldb you can override the debugDescription 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, whereas po calls debugDescription which by default calls description. Giving this you can differentiate the results of that calls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!