Thursday, June 28, 2012

Handle NSLog before release

Go to your Build settings and under the Debug configuration add a value to "Preprocessor Macros" value like:      DEBUG_MODE=1
Make sure you only do this for the Debug configuration and not for Beta or Release versions. Then in a common header file you can do something like:



#ifdef DEBUG_MODE
#define DLog( s, ... ) NSLog( @"<%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... )
#endif



Now instead of NSLog use DLog everywhere. When testing and debugging, you'll get debug messages. When you're ready to release a beta or final release, all those DLog lines automatically become empty and nothing gets emitted. This way there's no manual setting of variables or commenting of NSLogs required. Picking your build target takes care of it.

3 comments:

  1. great one.
    i was really aware of this even i dint event think about this trick. i manually comment every of my nslog before release. :)

    ReplyDelete
  2. We must appreciate this article, which is truly educational and informative too.
    http://www.imobdevtech.com/

    -----------------------------------------------------------------------------
    Php Development Services India, && Hire Titanium Developer

    ReplyDelete