Group Group Group Group Group Group Group Group Group

Chapter 8: Presenting a view controller as a Future

Hello, I have been trying the code related to the presentation of the Alert view controller as a Future, and I have some questions.

In order to dismiss the presented alert, you suggest to include a handleEvents(receiveCancel:) on the publisher:
func alert(title: String, text: String?) -> AnyPublisher<Void, Never> {
let alertVC = UIAlertController(title: title,
message: text,
preferredStyle: .alert)

    return Future { resolve in
      alertVC.addAction(UIAlertAction(title: "Close",
                                      style: .default) { _ in
        resolve(.success(()))
      })

      self.present(alertVC, animated: true, completion: nil)
    }
    .handleEvents(receiveCancel: {
        print("Received cancel Event")
       self.dismiss(animated: true)
    })
    .eraseToAnyPublisher()
  }

However, I do not see that the cancelation event gets triggered. In fact, we could completely remove the dismissal of the view, and we get the same behavior, the view gets dismissed as well. The only way I have managed to execute the cancellation handler is by not storing it in the subscriptions on the MainViewController. Is this the intended behavior, or is there something I am missing here?

@freak4pc Can you please help with this when you get a chance? Thank you - much appreciated! :]