How to determine whether code is running in DEBUG / RELEASE build?


I am making an app that processes sensitive credit card data.

If my code is running in debug mode I want to log this data to the console and make some file dumps.

However on the final appstore version (ie when it is running in release mode) it is essential all of this is disabled (security hazard)!

I will try to answer my question as best I can; so the question becomes 'Is this solution path the right or best way to do it?'

// add `IS_DEBUG=1` to your debug build preprocessor settings  

#if( IS_DEBUG )  
#define MYLog(args...) NSLog(args)  
#define MYLog(args...)  

This question is tagged with ios xcode debugging preprocessor release

~ Asked on 2012-01-30 11:26:26

The Best Answer is


Check your project's build settings under 'Apple LLVM - Preprocessing', 'Preprocessor Macros' for debug to ensure that DEBUG is being set - do this by selecting the project and clicking on the build settings tab. Search for DEBUG and look to see if indeed DEBUG is being set.

Pay attention though. You may see DEBUG changed to another variable name such as DEBUG_MODE.

Build Settings tab of my project settings

then conditionally code for DEBUG in your source files

#ifdef DEBUG

// Something to log your sensitive data here




~ Answered on 2012-01-30 11:53:15


For a solution in Swift please refer to this thread on SO.

Basically the solution in Swift would look like this:

    println("I'm running in DEBUG mode")
    println("I'm running in a non-DEBUG mode")

Additionally you will need to set the DEBUG symbol in Swift Compiler - Custom Flags section for the Other Swift Flags key via a -D DEBUG entry. See the following screenshot for an example:

enter image description here

~ Answered on 2015-05-03 12:03:25

Most Viewed Questions: