[ACCEPTED]-How do I declare a debug only statement-xcode
You can use
#ifdef DEBUG
....
#endif
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.
The NDEBUG symbol should be defined for 4 you already in release mode builds
#ifndef NDEBUG
/* Debug only code */
#endif
By using 3 NDEBUG you just avoid having to specify 2 a -D DEBUG argument to the compiler yourself 1 for the debug builds
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
#define DEBUGMODE YES
#else
#define DEBUGMODE NO
#endif
So 2 testing the DEBUGMODE value is much more 1 compact:
if (DEBUGMODE) {
//do this
} else {
//do that
}
My favourite:
NSTimeInterval updateInterval = DEBUGMODE?60:3600;
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.
Tony
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.