title: SwiftUI: How to execute closure when Alert is dismissed?
body: <p>I've been trying out swiftUI and looked at <a href="https://www.raywenderlich.com/3715234-swiftui-getting-started" rel="noreferrer">this Ray Wenderlich tutorial</a>... I noticed they didn't re-implement the "nextRound" functionality... so I tried to do it myself.  Ran into a problem (which maybe they did, also):</p>
  
  <p>The basic question is more general: </p>
  
  <p><em>Using swiftUI, how do you trigger a function when an Alert is dismissed -- when the user clicks "OK." ?</em></p>
  
  <p>I've tried using the dismissButton argument of the Alert constructor...</p>
  
  <p>(and also the .onDisappear method of View but I can't figure out how to apply it to the Alert view.)</p>
  
  <p>Code:</p>
  
  <pre><code>import SwiftUI
  
  struct ContentView: View {
  
      @State var shouldShowAlert: Bool = false
  
      // this never gets called
      func onAlertDismissed() {
          print("you will not see this in the console")
      }
  
      // this doesn't seem to work
      var dismissButton: some View {
  
          Button(action: {
              self.onAlertDismissed()
          }) {
              // Bilbo Baggins does not appear -- "OK" still shows
              Text("BILBO BAGGINS")
          }
      }
  
      var body: some View {
  
          VStack {
              Spacer()
  
              Button(action: {
                  self.shouldShowAlert = true
              }) {
                  Text("show the alert!")
              }
              Spacer()
          }.alert(isPresented: $shouldShowAlert, content: {
  
              // what to add here?
              Alert(title: Text("Alert:"), message: Text("press OK to execute onAlertDismissed()..."))
  
              // what I have tried and doesn't work:
              /*
               Alert(title: Text("Alert:"), message: Text("press OK to execute onAlertDismissed()..."), dismissButton: self.dismissButton as? Alert.Button)
               */
  
  
          })
  
      }
  }
  </code></pre>