Difference between NSLog and Printf statement for ObjectiveC

Rushi3311 picture Rushi3311 · Jan 25, 2012 · Viewed 23.7k times · Source

I want to know about the difference between the NSLog and the Printf statement in Objective-C (for application purpose...!)

Why do all developer use NSLog instead of Printf ?

Both look similar, but what is the difference in internal working?

At which point can they be differentiated ?

Answer

user529758 picture user529758 · Jan 25, 2012
  • printf() is a C standard library function, accepting a C string constant (const char *) as its format argument. printf() writes to stdout.

  • NSLog() is a Foundation function, accepting a constant NSString as format, and has an extended format specifier set (for example, printf() does't print objects specified by %@, NSLog() does). NSLog() also prints the process name and date before it prints the actual format and writes to sdterr.

Basically, we can say that NSLog() is an extended printf() Style function for Objective-C (more precisely, Cocoa and Cocoa Touch) and specific purposes.