sindresorhus / Settings

⚙ Add a settings window to your macOS app in minutes
MIT License
1.43k stars 100 forks source link

How do you use Preferences in a SwiftUI App View? #69

Open macaaw opened 3 years ago

macaaw commented 3 years ago

How do I use Preferences within SwiftUI app code? The only way I can see is to use Settings with a View.

WindowGroup { ContentView() }

Settings { MyCustomSettingsView() }

sindresorhus commented 3 years ago

Why would you use this there? You can just use Settings. No need for this package.

Sam-Spencer commented 1 year ago

@sindresorhus because SwiftUI doesn't provide a native way to present the Preferences window / add the menu item without doing what @macaaw demonstrates above. The example you provide in your README is out of date and doesn't work out of the box with SwiftUI.

HaarisIqubal commented 6 months ago

In swiftui you can use .commands modifier just below Window Group CommandGroup(replacing: .appSettings){ Button("Preferences..."){ SettingsWindowController(panes: [SettingsViewController.GeneralPreferenceViewController()], style: .toolbarItems, animated: true, hidesToolbarForSingleItem: true) .show() } .keyboardShortcut(KeyEquivalent(","), modifiers: .command) }