Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
735 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...