gpt4 book ai didi

swift - 错误 : Cannot convert value of type '(_) -> ()' to expected argument type '(() -> Void)?'

转载 作者:行者123 更新时间:2023-11-28 10:05:06 24 4
gpt4 key购买 nike

我最近从 swift3 迁移到了 swift 4.2。构建时我现在收到以下错误:

Cannot convert value of type '(_) -> ()' to expected argument type '(() -> Void)?'

错误出现在以下代码行中:

topWindow.rootViewController?.present(alert, animated: true, completion: { _ in })

我不太确定如何解决该错误。提供的任何帮助将不胜感激

    let topWindow = UIWindow(frame: UIScreen.main.bounds)

topWindow.rootViewController = UIViewController()
topWindow.windowLevel = UIWindow.Level.alert + 1
//let storyboard = UIStoryboard(name: "Main", bundle: nil)
// let topViewController = storyboard.instantiateViewController(withIdentifier: identifier) as? BaseViewController
let alert = UIAlertController(title: "iPanel", message: t_alert, preferredStyle: .alert)
let yesButton = UIAlertAction(title: get_error(eng_error: "open"), style: .default, handler: {(_ action: UIAlertAction) -> Void in
print("you pressed Yes, please button")
//topWindow.isHidden = true
//trying to fix reject 154 sending user to survey from push when app is in forground
//take user to controller
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ccontroller") as! UINavigationController
topWindow.rootViewController?.present(vc, animated: true, completion: nil)
}
})

let noButton = UIAlertAction(title: get_error(eng_error: "ignore"), style: .default, handler: {(_ action: UIAlertAction) -> Void in
print("you pressed No, thanks button")
topWindow.isHidden = true
})

alert.addAction(noButton)
alert.addAction(yesButton)

topWindow.makeKeyAndVisible()
topWindow.rootViewController?.present(alert, animated: true, completion: { _ in })
}

最佳答案

您不必填写 completion 参数,因为此参数具有 default value这是nil

topWindow.rootViewController?.present(alert, animated: true)

无论如何,如果你想声明completion,你不需要_ in因为completion不接受任何参数

topWindow.rootViewController?.present(alert, animated: true, completion: { })

或者只是

topWindow.rootViewController?.present(alert, animated: true) { }

关于swift - 错误 : Cannot convert value of type '(_) -> ()' to expected argument type '(() -> Void)?' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55122534/

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