You can use the description method in two ways. One, if in the code in your app somewhere you do:
NSLog(@"My Object: %@", my_object);
then %@
specifier will print the NSString returned by the "description" method of your object.
Another way is in the debugger:
lldb (and gdb before it) has a command called po
- which is short for print-object
. It's job is to take some expression, evaluate it, interpret the result (in the case of ObjC) as an NSObject and send that object the description
method.
So in the debugger you can just call
(lldb) po object
and get your printout.
One detail, though: po
actually first checks if the object responds to debugDescription
and it will call that in preference to description
. So if you are extending an object that implements debugDescription
(some Kit objects do this) then po
will show you the result of the debugDescription method, not your description.