Preprocessor conditional compilation

Swift 2.2
#if swift() >= 2.2
...
#endif

In order to make conditional code based on building in debug or the scheme, you need to add -D DEBUG yourself.

  1. Go to the file navigator, ⌘1
  2. Select the project (the first item)
  3. In the editor area, select the project and Build Settings
  4. Scroll all the way to the bottom, under Swift Compiler - Custom Flag
  5. Under Other Swift Flags, Debugging, add -D DEBUG
  6. The conditional code will look like this:
Swift 2.2
@IBAction func swipeAction(sender: UISwipeGestureRecognizer) {
    #if DEBUG
        priorElapsed = priorElapsed.advancedBy(10.0)
    #else
        print("swipe ignored in release mode")
    #endif
}

h/t

  • https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_13
  • http://stackoverflow.com/questions/9063100/xcode-ios-how-to-determine-whether-code-is-running-in-debug-release-build/30013587#30013587