Looking for objective-c Answers? Try Ask4KnowledgeBase
Looking for objective-c Keywords? Try Ask4Keywords

Objective-C Language Logging Variable Values


Example

You shouldn't call NSLog without a literal format string like this:

NSLog(variable);    // Dangerous code!

If the variable is not an NSString, the program will crash, because NSLog expects an NSString.

If the variable is an NSString, it will work unless your string contains a %. NSLog will parse the % sequence as a format specifier and then read a garbage value off the stack, causing a crash or even executing arbitrary code.

Instead, always make the first argument a format specifier, like this:

NSLog(@"%@", anObjectVariable);
NSLog(@"%d", anIntegerVariable);