5

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

Tharif
  • 13,538
  • 9
  • 54
  • 76
Milan Rathod
  • 336
  • 1
  • 2
  • 16

2 Answers2

6

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
dibi
  • 3,167
  • 4
  • 23
  • 31
4

Under the target's Build Settings search for "flags" and add -D TARGET_LITE to Swift Compiler - Custom Flags > Other Swift Flags:

enter image description here

Observe how it's getting passed to the compiler by looking in the build log (hard to read, sorry):

enter image description here

trojanfoe
  • 118,129
  • 19
  • 204
  • 237