How to conditionally compile based on target names?

I use the testflightapp.com SDK in my project to track crashes during beta testing on testflightapp.com. I have 2 goals in my Xcode project which are "ad-hoc" and "store app".

To run the testflight SDK, I need to specify a line of code in AppDelegate.m as:

[TestFlight takeOff:@"67bebb8d8e5396a...A4LjQwNjQ4NA"]; 

Now I want the compiler to exclude this line of code when compiling for the target "application store", because it makes no sense to run the testflight SDK when it goes public.

I expect something like #ifdef, but I couldn't figure it out by finding a forum.

+7
source share
1 answer

You can use the custom build parameter that you set in the build settings for each target, and then use #if or #ifdef to check this parameter. For example, select an ad-hoc target, click Build Settings, and scroll down to the Custom section. Then simply click on the โ€œAdd Build Settingsโ€ button and select โ€œAdd Custom Settings.โ€ You can set different values โ€‹โ€‹for your customization for each build configuration (debugging, release, etc.).

Picture of relevant Xcode settings

+10
source

All Articles