Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Multiple targets handling: macros not working [duplicate]

from the reference How to handle multiple targets in XCode using swift language? and https://www.appcoda.com/using-xcode-targets/

I have created three targets, each target having different bundle ids and app icons. I have also added different flag to the "Other swift flags" - > Custom swift flag section

like

for first target I added "-DGOLD" , for second target I added "-DSILVER" and for third target I added "-DPLATINUM".

In the AppDelegate I wrote a code

#if GOLD
print ("Gold")
#elseif SILVER
print ("Silver")
#else
print ("Platinum")
#endif

FYI, I am using Xcode 8.3

I tried to run the first target, I always getting "Platinum". Please provide me how to get the flags correctly

like image 786
Sridhar Avatar asked Sep 16 '25 17:09

Sridhar


1 Answers

I am working with Xcode 9. I am having same problem and looked for an answer for a few hours and finally found the solution. At each Target, Build Settings -> Other Swift Flags, I added the wanted flag like this:

Target1 -> -DTARGET1

Target2 -> -DTARGET2

Then in my code used:

#if TARGET1
//
#elseif TARGET2
//
#endif
like image 186
Techno Mag Avatar answered Sep 18 '25 06:09

Techno Mag