Alex Rivera | Logout

How can I add an #ifdef DEBUG to Xcode?

Asked 2011-11-24T12:46:40.597
22

I have some code in a project which should never be used in the release build, but is useful when testing. I'd like to do something like this:

#ifdef DEBUG
    // Run my debugging only code
#endif

Where do I add the DEBUG setting in Xcode 4? I tried putting it in the "Edit Scheme" under Run MyApp->Arguments Passed On Launch, but it didn't work. Alternatively, is there a flag already available for this?

Edit
Report

2 Answers

40

In recent Xcode project templates there’s already a DEBUG=1 macro defined for the Debug build configuration (in the Preprocessor Macros section). You can test it using the #if preprocessor directive.

answered 2011-11-24T12:48:20.070
6

I usually add my -DDEBUG=1 to the OTHER_C_FLAGS section in my XCode 4 project's build settings.

And yes, they can even discriminate between Debug / Release / ADHOC / Store builds.

answered 2011-11-24T12:56:17.283

Your Answer