Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
macaaw opened this issue Jul 4, 2021 · 3 comments
Open

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

macaaw opened this issue Jul 4, 2021 · 3 comments

Comments

@macaaw
Copy link

macaaw commented Jul 4, 2021

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
Copy link
Owner

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

dezinezync pushed a commit to dezinezync/Preferences that referenced this issue Dec 17, 2022
dezinezync pushed a commit to dezinezync/Preferences that referenced this issue Dec 17, 2022
@Sam-Spencer
Copy link
Sponsor

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants