4

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,172
  • 9
  • 51
  • 73
Milan Rathod
  • 316
  • 1
  • 2
  • 15

2 Answers2

4

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
Daniel
  • 2,977
  • 4
  • 22
  • 31
3

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
  • 116,099
  • 18
  • 197
  • 233