我升级到 Swift 3.1,我收到了一些新错误,这些错误似乎是 3.1 语法问题,因为在迁移之前它们不是问题。它们大多与闭包有关,如本例所示:
let alert = UIAlertController(title: "Success", message: "Thanks for participating in our raffle!", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: {
performSegue(withIdentifier: "to_root", sender: self)
}))
Cannot convert value of type '() -> Void' to expected argument type '((UIAlertAction) -> Void)?'
关于如何更正此问题以至少在短期内编译我的代码的任何想法?
谢谢。
最佳答案
您的处理程序的输入是 (UIAlertAction) 类型,因此只需将以下行添加到您的代码中。
handler: {
action in
完整的解决方案
let alertVC = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "Ok", style: .default, handler: {
action in
self.performSegue(withIdentifier: "go", sender: self)
}))
关于ios - swift 3.1 : Cannot convert value of type '(_) -> ()' error/Problems with closures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43589259/