01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Understanding NSLog<br />

279<br />

Figure 14.3 The Devices console section of the Organizer window shows log messages not only from<br />

your application’s NSLog calls but also from other system applications and iOS platform services.<br />

Scrolling through the console, you should be able to find the log entries produced by<br />

DebugSample’s calls to NSLog while the device was disconnected from the computer.<br />

While connected, if you launch the application on your device, you should even<br />

notice that the console window updates in real time.<br />

Although it can be handy during development to log a large amount of content via<br />

NSLog, it’s often less than desirable in builds which customers will obtain. Instead of<br />

manually commenting out unnecessary calls to NSLog, you can use some C preprocessor<br />

magic to automatically ensure calls to NSLog appear only in debug builds. Open the<br />

DebugSample_Prefix.pch file and insert the contents shown in the following listing.<br />

Listing 14.2<br />

Helpful macros that improve logging flexibility during development<br />

#ifdef DEBUG<br />

# define LogDebug(...) NSLog(__VA_ARGS__)<br />

#else<br />

# define LogDebug(...) do {} while (0)<br />

#endif<br />

#define LogAlways(...) NSLog(__VA_ARGS__)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!