In macOS 14.0 (Sonoma), Apple removed support for NSApp.sendAction
to open the Settings view in your SwiftUI app. You now have to use SettingsLink like below:
if #available(macOS 14.0, *) { // open Settings view on macOS 14.0+
SettingsLink {
HStack {
Image(systemName: "gearshape")
Text("Preferences")
}
}
} else { // open Settings view on macOS 13.0
Button {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
} label: {
HStack {
Image(systemName: "gearshape")
Text("Preferences")
}
}
}
And, if you want to support even older versions of macOS, you have to add one more if
condition and open the Settings view like below:
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)