Created
January 29, 2022 21:27
-
-
Save zentrope/158e4afc4bb90f1026bd0a1c35a9117c to your computer and use it in GitHub Desktop.
SwiftUI Toggle in menu items (macOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@main | |
struct TestApp: App { | |
@State var toggle = false | |
@State var other = true | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
.frame(minWidth: 1000, minHeight: 600) | |
} | |
.onChange(of: toggle) { flag in print("Toggle: \(flag)") } | |
.onChange(of: other) { flag in print("Other: \(flag)") } | |
.commands { | |
CommandMenu("Test") { | |
Toggle("Toggle", isOn: $toggle) | |
Toggle("Other Thing", isOn: $other) | |
} | |
} | |
Settings { | |
SettingsView() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment