I have created two targets in XCode but I am using swift. Can anybody know please how to handle multiple targets using swift? As we were doing in Objective-C as given in below example.
#if defined(TARGET_LITE)
NSLog("Lite version");
#else
NSLog("Original version");
#endif
Thanks in advance
Go to project's settings in the Project Navigator panel. Under the Targets sections, right click the existing target and select Duplicate to copy your existing target. 2. Xcode will ask you if your new target is for iPad development.
Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.
You could of cause use preprocessor statements like #if
in Swift but I think you need to define the target-variables by yourself. I am using it as follows:
Build Settings -> Swift Compiler Flags -> Other Swift Flags
Set a variable -D LITE
in your lite-target configuration
In your code you could use it like this:
#if LITE
// do something
#else
// do something else
#endif
Under the target's Build Settings search for "flags" and add -D TARGET_LITE
to Swift Compiler - Custom Flags > Other Swift Flags:
Observe how it's getting passed to the compiler by looking in the build log (hard to read, sorry):
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