Jac*_*nig 3 ios swift swift3.1
我升级到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)
}))
Run Code Online (Sandbox Code Playgroud)
无法将'() - > Void'类型的值转换为预期的参数类型'((UIAlertAction) - > Void)?'
关于如何纠正这个问题的任何想法,至少在短期内能够编译我的代码?
谢谢.
处理程序的输入是类型(UIAlertAction),所以只需在代码中添加以下行.
handler: {
action in
Run Code Online (Sandbox Code Playgroud)
完整解决方案
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)
}))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
493 次 |
| 最近记录: |