b2cloud

14th December 2012

Removing NSLogs for distribution

Guides | Tutorial By 4 years ago

When developing an iOS or Mac app, NSLogs are very handy during development. These are quite useless for an app on an end users phone or computer, so removing every log is often a good idea, especially if you like to log a lot of information. This might sound like a pain, commenting out every NSLog whenever you build for the AppStore? But no, there’s a much simpler solution, coming from our friend the preprocessor macro.

Every iOS and Mac project has a special file called <your project>-Prefix.pch. What does this mean? This is a precompiled header – a .h that is imported by every file in your project without the need to manually #import it. Combining this and preprocessor macros gives a very elegant solution to removing logs when building for the AppStore, and keeping them when developing.

Just put this into your pch:

#if DEBUG
#warning NSLogs will be shown
#else
#define NSLog(...) {}
#endif

Now try and build for development, you will get a warning telling you that logs will be shown. Build again for release and the macro replaces every NSLog (at compile time) with nothing.

  • Hemant Bosamia

    Hey Tom, just awesome. What a brilliant way to remove NSlogs. Thank you.

Recommended Posts

My Facebook advertising experience (Part 2)

Post by 4 years ago

A couple of weeks ago I posted a part 1 about my experience advertising with Facebook. The first campaign was advertising the lite version and monitoring both the lite and paid version downloads. After the

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!