Ultimate Catalyst Guide

How do I write code that only runs on macOS?

You can implement conditional code via the new targetEnvironment(UIKitForMac directive:

Compile code only on the macOS target

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

Compile code only on the iOS target

#if !targetEnvironment(UIKitForMac)
  import ARKit
#endif