Search code examples
iphoneobjective-ccocoa-touchuikitnslog

Is there an overview of all codes that can be used inside NSLog()?


i.e. %@ for strings, %f for doubles... I don't know the word for these placeholders but it would be great to have list for how to print booleans and other values.


Solution

  • Since NSLog takes a NSString as its argument, it uses the NSString format specifiers. This is virtually identical to the common printf specifiers. Also, the %@ specifier is not limited to NSString objects, but is for any Objective-C objects. The base NSObject class provides a generic description of the object consisting of its class and its address, but many objects will supply information specific to their type, such as the collection classes (NSArray, NSDictionary) which will supply nicely formated dump of their contents. You can provide this for your own objects that you create by overriding -description (see the documentation for more info, including localization capability).

    See also: NSString Format Specifiers