Open macaaw opened 3 years ago
Why would you use this there? You can just use Settings
. No need for this package.
@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.
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) }
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() }