How can I display an alert dialog box from a menu item for MacOS apps using SwiftUI?
The usual code which works for iOS @State var isOn = false and .alert("title", isPresented: isOn) {..} doesn't work.
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}.commands {
CommandMenu("Test menu") {
Button(action: {
// I want to show an alert dialog dialog here.
}) {
Text("Click Me")
}
}
}
}