How do I mark a source file as for debug builds only?

Discussion in 'Mac Programming' started by moonman239, Mar 25, 2016.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    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?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #3
    There's already a DEBUG in there that activates via a scheme in Xcode, right?
     
  4. Mernak macrumors 6502

    Joined:
    Apr 9, 2006
    Location:
    Kirkland, WA
    #4
    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.
     

Share This Page