I was following a tut and found a line of code like @"%@ button pressed.". I'm pretty sure the relevant part is the %@, but is the first @ an escape sequence or what?
Anyways, searching symbols doesn't go well in any search engine so I thought I'd ask. I think the %@ is like {0} in C#?
%@ is a format specifier. Functions such as NSLog and methods such as +stringWithFormat: will replace %@ with the description of the provided Objective-C or Core Foundation object argument.
For example:
NSString *myName = @"dreamlax";
NSLog (@"My name is: %@", myName);
This will log the output "My name is: dreamlax". See here for more information format specifiers.
The initial @ symbol at the beginning of the string tells the compiler to create a static instance of an NSString object. Without that initial @ symbol, the compiler will create a simpler C-style string. Since C-style strings are not Objective-C objects you cannot add them to NSArray or NSDictionary objects, etc.
@"some string" means this is an NSString literal.
The string as show in @"CupOverflowException", is a constant NSString object. The @ sign is used often in Objective-C to denote extentions to the language. A C string is just like C and C++, "String constant", and is of type char *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With