Search code examples
objective-cnslog

How to do not write log on release mode in iOS?


In my memory, there's some code that can let the NSLog not work when released.

I don't want to remove my NSLog in my code.It helps a lot on debug mode.

So I want to find a way that can leave them in my code, and also don't slow down the application when released.

Thanks for your help~~


Solution

  • A common way to remove all NSLog(…) call in a release is to create a macro that is between conditional preprocessor macro and compiles to nothing, something like this:

    #ifdef RELEASE
    # define NSLog(...) //remove loggin in production
    #endif
    

    Put this code in a .h file that is included in every other file, like a Defines.h that is #include'd in the prefix header (.pch).

    RELEASE should be a preprocessor macro defined against the Release configuration in the "Build Settings" tab of your target.

    Apple LLVM compiler 4.0 - Preprocessing

    Related Questions