I'm using testflightapp.com SDK in my project to track crashes during beta test which is conducted on testflightapp.com. I have 2 targets in my Xcode project, which are "ad-hoc" and "app store".
To initiate testflight SDK, I need to put down a line of code in the AppDelegate.m like:
[TestFlight takeOff:@"67bebb8d8e5396a...A4LjQwNjQ4NA"];
Now, I want the compiler to exclude this line of code when I compile for the target "app store", because it doesn't make sense to trigger testflight SDK when it goes to public.
I'm expecting something like #ifdef, but I couldn't get a clue by searching the forum.
You can use a user-defined build setting that you set in the build settings for each target, and then use an #if
or #ifdef
directive to test that setting. For example, select your 'ad-hoc' target, click on 'Build Settings', and scroll down to the 'User-Defined' section. Then just click the 'Add Build Setting' button and choose 'Add User-Defined Setting'. You can set different values for your setting for each build configuration (debug, release, etc.).
It is a old post but would like to share another way to achieve this.
The solution is like create few (depends on how much targets you have) files with same class/function/variable but added to different targets.
Like for me, I have main target and UITest target so I have following two files
BuildConfiguration_main.swift
added to main target.
struct BuildConfiguration {
static let isMainTarget = true
static let isUITestTarget = false
}
BuildConfiguration_UITest.swift
added to UITest target.
struct BuildConfiguration {
static let isMainTarget = false
static let isUITestTarget = true
}
Then in you code, you can use BuildConfiguration.isMainTarget
or BuildConfiguration.isUITestTarget
to tell where is target the code is running if you share some codes between two targets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With