In Xcode Organizer, Console - I can read the output of NSLog , but not printf() . Is it possible to read the result of printf() on a real device, the same as in the simulator?
NSLog
printf()
The simplest solution is to overload the printf function worldwide and replace it with NSLog output.
int printf(const char * __restrict format, ...) { va_list args; va_start(args,format); NSLogv([NSString stringWithUTF8String:format], args) ; va_end(args); return 1; }
As Nick Lockwood noted in one of the comments above, printf prints to stdout, but NSLog prints to stderr. You can use fprintf to print in stderr (Xcode console) instead of using printf, for example:
fprintf(stderr, "This prints to the Xcode debug console");
You can run the following command to print only on the deviceβs console:
syslog(LOG_WARNING, "log string");
You will also need #include <sys / syslog.h> for syslog and LOG_WARNING for an explicit declaration.
Skippy, printf () is the output operator for c, not for Objective-C, SO in the real device also printf () does not work.