Contents

environment

The environment for any scene(s) being represented by self.

Declaration

@MainActor var environment: EnvironmentValues { get }

Discussion

Use the environment values to programmatically present a scene’s window.

For example, you can present the window for a Settings scene using OpenSettingsAction when a menu item is selected:

let settingsScene = NSHostingSceneRepresentation {
    Settings {
        SettingsView()
    }
}

@IBAction func showAppSettings(_ sender: NSMenuItem) {
    settingsScene.environment.openSettings()
}