Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I'm going to create a source code file that is meant to be used only in a development environment. Is there a way to tell Xcode to compile the file only for debug builds?
 

chown33

Moderator
Staff member
Aug 9, 2009
11,003
8,899
A sea of green
Add a define to just the Debug build:
Code:
-DMOONMAN_DEBUG=1

Put this in your source file:
Code:
#if MOONMAN_DEBUG

...entire current source of file goes here...

#endif


Another alternative is two separate targets. One has the source file in the target, the other doesn't.
 
  • Like
Reactions: Madd the Sane

robvas

macrumors 68040
Mar 29, 2009
3,240
630
USA
There's already a DEBUG in there that activates via a scheme in Xcode, right?
 

Mernak

macrumors 6502
Apr 9, 2006
435
16
Kirkland, WA
What exactly are you trying to accomplish here? Having a different code path for testing usually means you aren't actually testing what is going to be used. I would suggest using proper mocks/stubs for testing (with separate build targets and injections), or passing a debug log level or similar if you want more info.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.