theWalker
theWalker

Reputation: 2020

iOS debugging real device with printf

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

Answers (4)

Elviss Strazdins
Elviss Strazdins

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

Swindler
Swindler

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

Sohaib
Sohaib

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

user1157838
user1157838

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

Related Questions