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, ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.