sindresorhus/Preferences

Do you want to work on this issue?

You can request for a bounty in order to promote it!

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

macaaw posted onGitHub

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() }


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

posted by sindresorhus over 3 years 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.

posted by Sam-Spencer over 1 year 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) }

posted by HaarisIqubal about 1 year ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests