Ultimate Catalyst Guide

Conditional Compilation

released Fri, 05 Jul 2019
Swift Version 5.1

If you want to compile code that runs only on macOS, you can do that by using the following, new compile time attribute:

#if targetEnvironment(UIKitForMac)
  let toolbar = NSToolbar(identifier: "MyToolbar")

Obviously, to do it the other way around, you just inverse it:

#if !targetEnvironment(UIKitForMac)
  import ARKit