I have created a simple macOS-only SwiftUI app and added a Settings screen as per Apple's instructions:
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
RootView()
}
Settings {
SettingsView()
}
}
}
It works: the Preferences option shows up in the app menu. Now, I would also like to open this settings window programatically, e.g. when a button is clicked. Is there a way to achieve this?
I was hoping there would be a method in NSApplication
, similar to the About window, but there doesn't seem to be one.