Present Popover in macOS

Does anyone have any idea how to present a popover from SwiftUI Button in a macOS application. I can't find any documentation on this anywhere.

Accepted Reply

Never mind, I figured it out.


@State private var showPopup = false

var body: some View {
     Button(action: {
          self.showPopup = true
     }) {
          Text("Popover Button")
     }
          .presentation(showPopup ? Popover(content: PopoverContent(), dismissHandler: { self.showPopup = false }) : nil)
}

Replies

Never mind, I figured it out.


@State private var showPopup = false

var body: some View {
     Button(action: {
          self.showPopup = true
     }) {
          Text("Popover Button")
     }
          .presentation(showPopup ? Popover(content: PopoverContent(), dismissHandler: { self.showPopup = false }) : nil)
}