Is there a macro that Xcode automatically sets in debug builds?
So I can write开发者_开发技巧 code like this:
#ifdef [whatever]
// do stuff that will never show up in the production version
#endif
Nothing useful per default, but you can set a DEBUG
macro for debug builds in the "Preprocessor Macros" of the targets build settings and then do:
#ifdef DEBUG
// do stuff
#endif
If you want to automate that, edit the project templates in "/Developer/Library/Xcode/Project Templates"
:
- Find the
XCBuildConfiguration
section(s) for whichname = Debug;
. - In the
buildSettings
addDEBUG
to the list forGCC_PREPROCESSOR_DEFINITIONS
if it exists - Otherwise add
GCC_PREPROCESSOR_DEFINITIONS = (DEBUG);
to thebuildSettings
For per-user customizations and to avoid them being overwritten, see this question.
If you can assume that debug builds always use gcc -O0
(this is normally the case, but there may be odd exceptions where someone has changed the optimisation level for debug builds) then you can do this:
#if __OPTIMIZE__
// ... non-debug stuff ...
#else
// ... debug stuff ...
#endif
精彩评论