How to open a unique window

Setting up a unique window that will never have copies or instances.

In visionOS 1 or 2 we could create force visionOS to treat windows as unique by opening them with an ID and passing the same value each time. This worked most of the time, but there were a few instances where it caused issues.

Starting in visionOS 26 we can create unique windows by using Window instead of WindowGroup. We pass a window title and an ID.

Window("Unique Rose Window", id: "RoseWindow") {
    RoseFlowerView()
}

As far as can tell, the title is ignored on visionOS. It may appear in the window bar on other platforms.

Take a look at this short demo. We adapted this example to include a new unique window. We can open more than one copy of the Yellow flower window, but only a single instance of the Rose window.

visionOS Simulator video showing two methods for opening windows. We can open more than one copy of the Yellow flower window, but only a single instance of the Rose window.

Example Code

App Code

struct Garden01App: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }

        WindowGroup(id: "YellowFlower") {
            YellowFlowerView()
        }

        Window("Unique Rose Window", id: "RoseWindow") {
            RoseFlowerView()
        }
    }
}

Sample code is available in Garden01 in Step Into Example Projects

Download the Xcode project with this and many more examples from Step Into Vision.

Some examples are provided as standalone Xcode projects. You can find those here.

Questions or feedback?