错误:无法将类型'(_) - >()'的值转换为预期的参数类型'(() - > Void)?'

问题描述 投票:0回答:2

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

无法将'(_) - >()'类型的值转换为预期的参数类型'(( - - > 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 })
}
swift swift4.2 xcode10.1
2个回答
4
投票

你不必填充completion参数,因为这个参数有default value,这是nil

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

无论如何,如果你想宣布qazxsw poi,你不需要qazxsw poi,因为qazxsw poi不带任何参数

completion

要不就

_ in

0
投票

最后一行的编译应为零 - 错误与此有关。

completion
© www.soinside.com 2019 - 2024. All rights reserved.