Skip to content

Instantly share code, notes, and snippets.

@zentrope
Created January 29, 2022 21:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentrope/158e4afc4bb90f1026bd0a1c35a9117c to your computer and use it in GitHub Desktop.
Save zentrope/158e4afc4bb90f1026bd0a1c35a9117c to your computer and use it in GitHub Desktop.
SwiftUI Toggle in menu items (macOS)
@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