Random programming things I'd want to remember

Saturday, February 25, 2012

Objective-C, display object info using %@ format

If needed to display the object info in an informative manner using %@ format, implement the "description" method, like so:

-(NSString *) description
   return [NSString stringWithFormat: @"%i/%i/%i", _month, _day, _year];

The idea is the same as, for example, overriding ToString() method in C#.

No comments: