concept NSLog in category ios

This is an excerpt from Manning's book Objective-C Fundamentals.
The first argument provided in a call to NSLog specifies what is called the format string. NSLog processes this string and displays it in the Xcode debugger console. In most cases, the format string contains one or more placeholders that are indicated by a % character. If placeholders are present, NSLog expects to be passed a matching number of additional arguments. As NSLog emits its message, it substitutes each placeholder with the value of the next argument. As an example, when the following code snippet is executed, NSLog replaces the first instance of %d with the value of variable a and the second instance with the value of variable b, resulting in the string "Current values are 10 and 25" being emitted to the debug console:
In this book you’ve utilized the NSLog function extensively to emit diagnostic messages to the Xcode debugger console window. What you may not realize is that NSLog continues to log messages even when your application is used outside of the debugger. It even logs messages once a user purchases your application from the iTunes App Store and runs it on their own device. Where do these log messages end up, and how do you retrieve them?
Figure 14.3. The Devices console section of the Organizer window shows log messages not only from your application’s NSLog calls but also from other system applications and iOS platform services.
![]()
Scrolling through the console, you should be able to find the log entries produced by DebugSample’s calls to NSLog while the device was disconnected from the computer. While connected, if you launch the application on your device, you should even notice that the console window updates in real time.
Although it can be handy during development to log a large amount of content via NSLog, it’s often less than desirable in builds which customers will obtain. Instead of manually commenting out unnecessary calls to NSLog, you can use some C preprocessor magic to automatically ensure calls to NSLog appear only in debug builds. Open the DebugSample_Prefix.pch file and insert the contents shown in the following listing.
Listing 14.2 defines two C preprocessor macros called LogAlways and LogDebug. LogAlways is an alias for NSLog. The definition of LogDebug alters depending on whether or not the state of DEBUG is defined. If DEBUG is defined, LogDebug is defined to be a call to NSLog, but if DEBUG isn’t defined, the following do while statement is substituted for calls to LogDebug: