gpt4 book ai didi

ios - swift 3.1 : Cannot convert value of type '(_) -> ()' error/Problems with closures

转载 作者:搜寻专家 更新时间:2023-10-31 22:11:38 26 4
gpt4 key购买 nike

我升级到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com