iosiphonenslog

Do I need to disable NSLog before release Application?


When releasing an app for iPhone, if I disable NSLog(); will it perform better?


Solution

  • One way to do it is to go into 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( @"<%p %@:(%d)> %@", self, [[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.