Using NSHostingSceneRepresentation to open arbitrary window in AppKit app

I’m trying to open a window from a SwiftUI Scene inside an AppKit app using NSHostingSceneRepresentation (macOS 26). The idea is that I want to call openWindow(id: "some-id") to show the new window.

However, nothing happens when I try this — no window appears, and there’s nothing in the logs. Interestingly, if I use the openSettings() route instead, it does open a window.

Does anyone know the correct way to open an arbitrary SwiftUI window scene from an AppKit app?

import Cocoa
import SwiftUI


@main class AppDelegate: NSObject, NSApplicationDelegate {

    let settingsScene = NSHostingSceneRepresentation {
        #if true
            MyWindowScene()
        #else
            Settings {
                Text("My Settings")
            }
        #endif
    }


    func applicationWillFinishLaunching(_ notification: Notification) {
        NSApplication.shared.addSceneRepresentation(settingsScene)
    }


    @IBAction func showAppSettings(_ sender: NSMenuItem) {
        #if true
            settingsScene.environment.openWindow(id: MyWindowScene.windowID)
        #else
            settingsScene.environment.openSettings()
        #endif
    }

}



struct MyWindowScene: Scene {

    static let windowID = "com.company.MySampleApp.myWindow"

    var body: some Scene {
        Window("Sample Window", id: MyWindowScene.windowID) {
            Text("Sample Content")
                .scenePadding()
        }
    }

}
Using NSHostingSceneRepresentation to open arbitrary window in AppKit app
 
 
Q