I am trying to refactor my UIAlertViewController
and pass a function to be executed when a user chooses to tap on one of two options which triggers an action.
My question is how do I go about adding a function as a parameter to a custom function? My effort is below. It is incomplete but any guidance would be much appreciated. I would like to have the function 'performNetworkTasl' as a parameter to 'showBasicAlert'.
import Foundation
import UIKit
struct Alerts {
static func showBasicAlert(on vc: UIViewController, with title: String, message: String, function: ?????){
let alert = UIAlertController.init(title: title, message: message, preferredStyle: .alert)
let okAction = UIAlertAction.init(title: "OK", style: .default) { (UIActionAlert) in
performNetworkTasl()
vc.dismiss(animated: true, completion: nil)
}
alert.addAction(okAction)
}
}
func performNetworkTasl(){
// DO SOME NETWORK TASK
}