I have a project that needs to support an old version of iOS and I'm trying to use SwiftUI for a view that will only appear when the user is on iOS 13 or later. The SwiftUI Preview in Xcode works just fine, but when I extend a SwiftUI struct (such as View), the project will compile and run on a device, but the Preview Canvas crashes, stating that it Failed to build myView.swift. When I click on the "diagnostics" button, it tells me that 'View' is only available in iOS 13.0 or newer and add @available attribute to enclosing extension. However, the extension in question already has @available(iOS 13.0, *) before it. For example:
@available(iOS 13.0, *)
extension View {
func myFunc() {
}
}
In an effort to find the root of this problem, I noticed that the preview won't crash if it's completely empty. Only once I add a function or static property to it will the canvas crash. I have also tried adding the @available line before each function in the extension, rebooting my computer, and deleting the DerivedData folder, but it doesn't seem to have made a difference.