Reputation:
I'm working through a BNR iOS Programming text and I came across this piece of code:
NSLog(@"%@", [items objectAtIndex:i]);
I am unsure of what "%@" is used for. I've seen other formats for referencing integers or characters, but I've never seen this.
I even checked this reference here and it had nothing.
Thanks!
Upvotes: 1
Views: 5156
Reputation: 86
I am working through the same text - and coming from a Java background, the "%@" formatter seems equivalent to the "toString" method that Java would have. It is used to display custom information about an object.
There is a good example in the response to this StackOverflow question about the "toString()" equivalent.
Upvotes: 0
Reputation: 44886
According to Apple:
Objective-C object, printed as the string returned by
descriptionWithLocale:
if available, ordescription
otherwise. Also works withCFTypeRef
objects, returning the result of theCFCopyDescription
function.
Reference:
Upvotes: 0
Reputation: 7344
%@ is for printing objective-c objects.
To be a bit more precise. Every object is able to override
-(NSString *)description
This method is called when you use %@. It depends on the object what info of the object it will return in the NSString
.
Upvotes: 6