Objective-C Language Formatting


Example

The NSString formatting supports all the format strings available on the printf ANSI-C function. The only addition made by the language is the %@ symbol used for formatting all the Objective-C objects.

It is possible to format integers

int myAge = 21;
NSString *formattedAge = [NSString stringWithFormat:@"I am %d years old", my_age];

Or any object subclassed from NSObject

NSDate *now = [NSDate date];
NSString *formattedDate = [NSString stringWithFormat:@"The time right now is: %@", now];

For a complete list of Format Specifiers, please see: Objective-C, Format Specifiers, Syntax