swiftuitargetcatalyst

Is there a targetEnvironment for macCatalyst in SwiftUI?


how to make a conditional view in SwiftUI with a targetEnvironment which checks for macCatalyst?

Something like:

#if targetEnvironment(macCatalyst)
    print("macOS")
#else
    print("Your regular code")
#endif

But directly in SwiftUI


Solution

  • enter image description here

    struct ContentView: View {
        var body: some View {
            VStack {
    #if targetEnvironment(macCatalyst)
                Button("Catalyst Demo") { }
    #endif
                Text("Hello, World!")
            }.frame(width: 300, height: 200)
        }
    }