Previously, declaring conditional compilation flags was done in the OTHER_SWIFT_FLAGS build setting. The tricky part when adding a flag was remembering to prepend -D like -DBETA. Forgetting the flag could lead to unexpected results or time wasted to debugging.

Other Swift Flags in Xcode

Enter Active Compilation Conditions.

Active Compilation Conditions

As of Xcode 8, we have the new SWIFT_ACTIVE_COMPILATION_CONDITIONS build setting which allows us to define our flags without the need to prefix them. Under the hood, each element is passed to swiftc prefixed with -D 👏🏽! This matches the behavior we had with Objective-C and Preprocessor Macros.

Active Compilation Conditions in Xcode


Regardless of which setting you choose to add it to, using the flag in your Swift project is the same:

#if BETA
  let backgroundQueue = ""
  let backgroundQueue = ""