Using Foundation’s NSLog Function
NSLog is a Foundation function that allows you to print debugging output to the console. This works much like the following C function.
CODE:
-
fprintf(stderr, format_string, args ...);
NSLog takes in a format string that is actually an NSString. You can use it in the usual ways such as the following.
OBJC:
The above code will output the following
number = 5
num = 4
NSLog will accept the following format specifiers.
| Format Specifier | Description |
| %@ | Cocoa Object responding to -description |
| %d, %i | Signed Integer |
| %u | Unsigned Integer |
| %f | Float / Double |
| %x, %X | Hexidecimal Integer |
| %o | Octal Integer |
| %zu | size_t |
| %p | Pointer |
| %e | Float / Double (in scientific notation) |
| %g | Float / Double (as %f or %e, based on value) |
| %s | C String |
| %.*s | Pascal String |
| %c | Character |
| %C | Unicode Character |
| %ll | Long Long |
| %llu | Unsigned Long Long |
| %Lf | Long Double |
NSLog() comes in very handy when you are debugging your code, it allows you to place messages throughout your code and see the messages while your application is running.






