0
votes

When I go to view my SwiftUI through the canvas preview in Xcode 11.3.1 I am getting the error

Compiling failed: 'Color' is only available in iOS 13.0 or newer

But the project itself builds successfully and the simulator loads without any issues. I have tried clearing the build folder, quitting Xcode and rebuilding but still no luck.

Any help would be great. Thanks in advance.

3
Is this SwiftUI only project? Which is deployment target version? - Asperi
@Asperi No, the project also has files using UIKIt and the deployment target is 11.4. Thanks - user2047296
I don't get the question. If your deployment target is 11.4 but Color is only available in 13.0, then that's the issue. Just bump up the deployment target to 13.0, or don't use Color. - LinusGeffarth

3 Answers

0
votes

SwiftUI minimum deployment target is 13.0, so if you have project with support of older version, then all SwiftUI code (including preview providers) you have to prepend with availability modifier, like

@available(iOS 13.0, *)  // << here !!
struct Demo: View {
    var body: some View {
        VStack {
            Text("Hello")
        }
    }
}
0
votes

You Should use Assets or Other option like Color Literal for Color. Don't use the system Color option since your deployment target is 11.4.

0
votes

Man, I've had a similar issue. The problem was that sometimes my preview worked sometimes it didn't... I reviewed the diagnostics and realized that there are some @_dynamicReplacement attributes mentioned (which are used, I guess, for hot reloading). It wasn't working when I've had a file with @available attributes opened in the (adjacent) editor. When I closed that editor everything worked back again.

Magic ✨

Also one more hint from my friend - when you have a file from another target (not the one hosting your Canvas-related code) in (adjacent) editor it behaves the same way.