How to determine whether code is running in DEBUG / RELEASE build?
Apple already includes a DEBUG
flag in debug builds, so you don't need to define your own.
You might also want to consider just redefining NSLog
to a null operation when not in DEBUG
mode, that way your code will be more portable and you can just use regular NSLog
statements:
//put this in prefix.pch
#ifndef DEBUG
#undef NSLog
#define NSLog(args, ...)
#endif
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.
then conditionally code for DEBUG in your source files
#ifdef DEBUG
// Something to log your sensitive data here
#else
//
#endif
For a solution in Swift please refer to this thread on SO.
Basically the solution in Swift would look like this:
#if DEBUG
println("I'm running in DEBUG mode")
#else
println("I'm running in a non-DEBUG mode")
#endif
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: