IPhone debugs a real device

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?

+8
debugging objective-c iphone printf
source share
4 answers

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; } 
+17
source share

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"); 
+8
source share

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.

+4
source share

Skippy, printf () is the output operator for c, not for Objective-C, SO in the real device also printf () does not work.

-one
source share

All Articles