What is the Objective-C equivalent for "toString()", for use with NSLog?

Solution 1:

It is the description instance method, declared as:

- (NSString *)description

Here's an example implementation (thanks to grahamparks):

- (NSString *)description {
   return [NSString stringWithFormat: @"Photo: Name=%@ Author=%@", name, author];
}

Solution 2:

Add this to the @implementation of your Photo class:

- (NSString *)description {
   return [NSString stringWithFormat:@"Photo: Name=%@ Author=%@",name,author];
}