Organizational Research By

Surprising Reserch Topic

xcode ios how to determine whether code is running in debug release build

xcode ios how to determine whether code is running in debug release build  using -'ios,xcode,debugging,preprocessor,release'

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...)  


asked Oct 13, 2015 by kotmus2002
0 votes

Related Hot Questions

5 Answers

0 votes

Check your project's build settings under 'Apple LVM - 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 Oct 13, 2015 by mannar kande
0 votes

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 as an example:

enter image description here

answered Oct 13, 2015 by akhilesh
0 votes

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, ...)
answered Oct 13, 2015 by nikhilapatil
0 votes

zitao xiong's answer is pretty close to what I use; I also include the file name (by stripping off the path of FILE).

#ifdef DEBUG
    #define NSLogDebug(format, ...) \
    NSLog(@"<%s:%d> %s, " format, \
    strrchr("/" __FILE__, '/') + 1, __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__)
    #define NSLogDebug(format, ...)
answered Oct 13, 2015 by nimisha.jagtap
0 votes

Not sure if I answered you question, maybe you could try these code:

#ifdef DEBUG
#define DLOG(xx, ...)  NSLog( \
    @"%s(%d): " \
    xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__ \  
#define DLOG(xx, ...)  ((void)0)
answered Oct 13, 2015 by vijaygupta1980