April 8, 2009 § Leave a comment
You can create a NSString by creating a ‘static” instance by using @”…” construct.
NSString *variable = @”Sample”;
You can also create NSString using class method +stringWithFormat:. It functions similar to the printf function of the standard C library. It didn’t send to the standard output, instead it is put in a NSString.
int players = 50;
game = [NSString stringWithFormat: @”This game accepts %d players”, players];
game will return a NSString containing “This game accepts 50 players”.
You can also use %@ specification to output a description of an object using NSObject -description for debugging.
NSObject *object = [myObject myMethod];
NSLog (@”The method returned: %@”, object);