4

So I can write code like this:

#ifdef [whatever]
   // do stuff that will never show up in the production version
#endif
William Jockusch
  • 26,513
  • 49
  • 182
  • 323

2 Answers2

5

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 which name = Debug;.
  • In the buildSettings add DEBUG to the list for GCC_PREPROCESSOR_DEFINITIONS if it exists
  • Otherwise add GCC_PREPROCESSOR_DEFINITIONS = (DEBUG); to the buildSettings

For per-user customizations and to avoid them being overwritten, see this question.

Community
  • 1
  • 1
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
3

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
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • I've read that __OPTIMIZE__ is not set anymore in XCode 4 all the time. Do you confirm this ? – Oliver Jun 29 '13 at 00:27