How to open the ContentView from a function when the Ok button is clicked?

There is such a function:

  func didFinishConfirmation(paymentMethodType: 
  YooKassaPayments.PaymentMethodType) {   

    DispatchQueue.main.async { [weak self] in
        guard let self = self else { return }
        let alertController = UIAlertController(
            title: "Confirmation",
            message: "Profit!",
            preferredStyle: .alert
         )
        let action = UIAlertAction(title: "OK", style: .default)
        alertController.addAction(action)
        self.dismiss(animated: true)
        self.present(alertController, animated: true)
    }
}

How to make it so that when clicking on the Ok button when an alert appears, the ContentView () in SwiftUI opens?

You do not define any handler for action.

I would:

  • create a Bool State var showContent, initiated as false
  • in the action handler, turn to true
  • In the View, test
if showContent { ContentView() }

Note: in Swift you can now write

        guard let self else { return }
How to open the ContentView from a function when the Ok button is clicked?
 
 
Q