Logging Variable Values

suggest change

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);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents