Objective-C Language NSString Formatting

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

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



Got any Objective-C Language Question?