How to target SwiftUI code to only the visionOS platform (Compiler Directive)

I am trying to do the following code:


    func withBackground() -> some View {
        #if os(visionOS)
        background {
            Material.thin
        }
        #else
        background {
            Color.offWhite.ignoresSafeArea()
        }
        #endif
    }

But Xcode 15 Beta 2 says the following:

Unknown operating system for build configuration os

How can I change the background ONLY for visionOS, while keeping it as is on the other platforms I support? Thanks!

Post not yet marked as solved Up vote post of deepstiker Down vote post of deepstiker
885 views

Replies

Note: I have added Vision as a target, not just the "Designed for iPad" target

Upon further digging, it seems like I have to use xrOS as the target, but the xrOS specific changes don't take effect because the simulator is trying to run it in a Designed for iPad mode. How can we run this as a native visionOS app?

  • Go to the app target and add Apple Vision as a Supported Destination (and remove the Apple Vision (designed for iPad) destination.

  • I did this, but the platform specific code still doesnt work.

Add a Comment