Mac Catalyst Swift Compiler Error

Hi,

I enabled Mac Catalyst (macOS12.1) for an app, set Optimise Interface for Mac with the following code. The code can be compiled with "Build Succeeded" and can be run successfully on an M1 Mac. However the editor will flag out the following:

'horizontalSizeClass' is unavailable in macOS

and with build time issues. If I use UIViewControllerRepresentable it will give

Cannot find type 'UIViewControllerRepresentable' in scope

The app does run ok. Am I missing something?

import SwiftUI

struct ContentView: View {

@Environment(.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass?

    var body: some View {

        if horizontalSizeClass == .compact {

            Text("Compact")

        } else {

            Text("Regular")

        }

        

     }

}

Thanks in advance.

What do you mean by “flag out”? Did the compiler issue a warning?

Thanks for looking into this. Build Succeeded with the following issues. I can also run and test the Mac Catalyst app.

Mac Catalyst Swift Compiler Error
 
 
Q