有没有办法将数组“listINeed”传递给处理函数“handleConfirmPressed”?我可以通过将它添加为类变量来做到这一点,但这看起来很hacky,现在我想为多个变量执行此操作,所以我需要一个更好的解决方案。
func someFunc(){
//some stuff...
let listINeed = [someObject]
let alert = UIAlertController(title: "Are you sure?", message: alertMessage, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Confirm", style: .Destructive, handler: handleConfirmPressed))
presentViewController(alert, animated: true, completion: nil)
}
func handleConfirmPressed(action: UIAlertAction){
//need listINeed here
}