This doesn't compile
func showAlert(_ title: String, message: String, onOk: (()->())? = nil, onAnotherAction:((anotherActionTitle : String)-> Void)? = nil) { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) let ok = UIAlertAction(title: "OK", style: .default) { (action) in onOk?() } let anotherAction = UIAlertAction(title: anotherActionTitle, style: .default) { (action) in onAnotherAction?() } alertController.addAction(ok) alertController.addAction(anotherAction) ... } This compiles
func showAlert(_ title: String, message: String, onOk: (()->())? = nil, onAnotherAction:((String)-> Void)? = nil) However, I have to declare another parameter for the title anotherActionTitle of onAnotherAction().
Is there a way make the first approach work? Thanks!