user1257724
user1257724

Reputation:

Objective-C - NSLog - "%@" Referencing Character

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

Answers (3)

declanh
declanh

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

Steven Fisher
Steven Fisher

Reputation: 44886

According to Apple:

Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.

Reference:

Upvotes: 0

Pfitz
Pfitz

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

Related Questions