NSHostingSceneRepresentation
, introduced in macOS 26, allows calling SwiftUI’s windows and other elements set in a Scene from AppKit. However, while Settings
and WindowGroup
set in the Scene
can be invoked as expected using environment.openSettings()
and environment.openWindow(id:)
respectively, calling Window
or WindowUtility
doesn’t work. That is, the app just fails to open the desired window with the provided ID, and no error message or other feedback/crash/freeze appears.
I expect that executing the openUtilityWindow(_:)
action in the following code will display the UtilityWindow set in the scene
. However, the window does not actually open.
@main
final class AppDelegate: NSObject, NSApplicationDelegate {
private let scene = NSHostingSceneRepresentation {
UtilityWindow("Utility Window", id: "UtilityWindow") {
Text("Utility Window")
.scenePadding()
}
}
func applicationWillFinishLaunching(_ notification: Notification) {
NSApp.addSceneRepresentation(self.scene)
}
@IBAction func openUtilityWindow(_ sender: Any?) {
self.scene.environment.openWindow(id: "UtilityWindow")
}
}
Is there something wrong with my implementation and expectation? Or is this a bug in NSHostingSceneRepresentation
?
Just in case, I’ve already filed this issue withFeedback Assistant: FB20310722
This feedback also includes a sample project reproducing this issue.