Loading...

How to open the Settings view in a SwiftUI app on macOS 14.0 (Sonoma)?

question swiftui swift
Ram Patra Published on September 30, 2023

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)
Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on September 30, 2023
Image placeholder

Keep reading

If this article was helpful, others might be too

question swiftui swift September 7, 2024 How to apply mirroring to any SwiftUI view?

You can apply mirroring to a SwiftUI view by using the scaleEffect(x:y:anchor:) modifier to flip the view horizontally or vertically. Specifically, you can set the x or y scale to -1.0 to mirror the view along that axis.

question swiftui swift September 8, 2024 How to loop through an enum in SwiftUI?

In SwiftUI, looping through an enum is not directly possible without some extra work because enums in Swift don’t inherently support iteration. However, you can achieve this by making the enum CaseIterable, which automatically provides a collection of all cases in the enum.