[ACCEPTED]-How do I declare a debug only statement-xcode

Accepted answer
Score: 69

You can use

#ifdef DEBUG

You'll need to add DEBUG=1 to the project's 8 preprocessor symbol definitions in the Debug 7 configuration's settings as that's not done 6 for you automatically by Xcode.

I personally 5 prefer doing DEBUG=1 over checking for NDEBUG=0, since 4 the latter implies that the default build 3 configuration is with debug information 2 which you then have to explicitly turn off, whereas 1 'DEBUG=1' implies turning on debug only code.

Score: 49

The NDEBUG symbol should be defined for 4 you already in release mode builds

#ifndef NDEBUG
/* Debug only code */    

By using 3 NDEBUG you just avoid having to specify 2 a -D DEBUG argument to the compiler yourself 1 for the debug builds

Score: 15

DEBUG is now defined in "debug mode" by 8 default under Project/Preprocessor Macros. So 7 testing it always works unless you have 6 a very old project.

However I hate the fact 5 that it messes up the code indentation and 4 not particularly compact. That is why I 3 use another macro which makes life easier.

#ifdef DEBUG

So 2 testing the DEBUGMODE value is much more 1 compact:

//do this
} else {
//do that

My favourite:

NSTimeInterval updateInterval = DEBUGMODE?60:3600; 
Score: 5

There is a very useful debugging technote: Technical 3 Note TN2124 Mac OS X Debugging Magic http://developer.apple.com/technotes/tn2004/tn2124.html#SECENV which 2 contains lots of useful stuff for debugging 1 your apps.


More Related questions