The description Method
You can also use the %@ format characters to display the entire contents of arrays, dictionaries, and sets. In fact, you can use them to display objects from your own classes, as well, as long as you override the description method inherited by your class. If you do not override the method, NSLog simply displays the name of the class the object belongs to and the address of the object in memory. That is the default implementation for the description method inherited from the NSObject class.
Following is an example of a description method that you could add to your Fraction class’s implementation section to have it format a Fraction object. This uses NSString’s stringWithFormat: method; a method that resembles NSLog but, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access