extension UIViewController {
func showAlertConfirm(errorMessage: String, operation: @escaping ()->()) {
let alert = UIAlertController(title: "Confirmation", message: errorMessage,
preferredStyle: .alert)
let confirmationAction = UIAlertAction(title: "OK", style: .default) { (action)
in
operation()
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler:nil)
alert.addAction(confirmationAction)
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)
}
}
если вы вызываете эту функцию
showAlertConfirm(errorMessage: "Test", operation:
requestData()
)