Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Objective-c Compile Time Conditional

I'm working on an iOS project in xcode and I'd like to include different codes depending on the build scheme. ie: For anything except the Distribution on an iOS Device scheme, I'd like to include a bunch of debug stuff. But for the Distribution on an iOS Device scheme, I don't want to include the debug stuff.

If I can add some sort of conditional code block it will be very helpful as it will eliminate the chance of me forgetting to change the flag manually.

Thanks!

like image 425
Wise Shepherd Avatar asked Jan 17 '26 22:01

Wise Shepherd


1 Answers

By default when you create a new XCode 4 project it will add DEBUG to your GCC_PREPROCESSOR_DEFINITIONS (Preprocessor Macros) under build settings so you can do the following.

#ifdef DEBUG
    //Debug only code here
#endif

If you need more preprocessor definitions add them under GCC_PREPROCESSOR_DEFINITIONS or OTHER_CFLAGS or OTHER_CPLUSPLUSFLAGS [prefix the last 2 with -D] for the correct build configuration.

like image 158
Joe Avatar answered Jan 19 '26 18:01

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!