Objective-C Language Logging NSLog vs printf

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

NSLog(@"NSLog message");
printf("printf message\n");

Output:

2016-07-16 08:58:04.681 test[46259:1244773] NSLog message
printf message

NSLog outputs the date, time, process name, process ID, and thread ID in addition to the log message. printf just outputs the message.

NSLog requires an NSString and automatically adds a newline at the end. printf requires a C string and does not automatically add a newline.

NSLog sends output to stderr, printf sends output to stdout.


Some format-specifiers in printf vs NSLog are different. For example when including a nested string, the following differences incur:

NSLog(@"My string: %@", (NSString *)myString);
printf("My string: %s", [(NSString *)myString UTF8String]);


Got any Objective-C Language Question?