Reputation: 2020
In Xcode Organizer, Console - I can read the NSLog
output, but not printf()
. Is this possible to read printf()
result on the real device, the same like in simulator?
Upvotes: 11
Views: 10883
Reputation: 1474
You can run the following command to print only to device's console:
syslog(LOG_WARNING, "log string");
You will also need to #include <sys/syslog.h> for syslog and LOG_WARNING to be explicitly declared
Upvotes: 4
Reputation: 810
As Nick Lockwood said in one of the comments above, printf prints to stdout but NSLog prints to stderr. You can use fprintf to print to stderr (the Xcode console) instead of using printf, like this:
fprintf(stderr, "This prints to the Xcode debug console");
Upvotes: 10
Reputation: 11297
Easiest solution would be to overload printf function globally in your project 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;
}
Upvotes: 18
Reputation: 131
Skippy,printf() is the output statement for c not for Objective C,SO in real device also printf() is not work.
Upvotes: -1