Metal iOS gives compile error

UPDATE:
Simulator support is coming this year (2019)

Pre Xcode 11/iOS 13:
Metal code doesn't compile on the Simulator. Try compiling for a device.


If your app has a fallback or mode that doesn't depend on Metal, and you want to compile your app for the simulator, you can do something like this:

#if targetEnvironment(simulator)
// dummy, do-nothing view controller for simulator
class ViewController: UIViewController {

}
#else
class ViewController: UIViewController {

    var device: MTLDevice! = nil
    var metalLayer: CAMetalLayer! = nil

    override func viewDidLoad() {
        super.viewDidLoad()
        device = MTLCreateSystemDefaultDevice()
        metalLayer = CAMetalLayer()
        ...
    }

}
#endif

Then your code will at least compile for both device and simulator, which can ease your non-Metal development.

Tags:

Ios

Swift

Metal