【问题标题】:Swift Cannot convert value of type to expected argument typeSwift 无法将类型的值转换为预期的参数类型
【发布时间】:2017-02-07 14:50:40
【问题描述】:
override func viewDidLoad() {
    super.viewDidLoad()
    let ref = FIRDatabase.database().reference()
    ref.observe(.value, with: {
    snapshot in
        self.label1.text = (snapshot.value as AnyObject)["label"] as! String
    }, withCancel: {
    error in
    print(error.description)
    })
    // Do any additional setup after loading the view, typically from a nib.
}

}, withCancel: { 行显示编译器错误:

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

【问题讨论】:

    标签: swift xcode


    【解决方案1】:

    试试这个

    override func viewDidLoad() {
        super.viewDidLoad()
        let ref = FIRDatabase.database().reference()
        ref.observe(.value, with: {
        snapshot in
            self.label1.text = (snapshot.value as AnyObject)["label"] as! String
        }, withCancel: {
        (error:Error) -> Void in
        print(error.description)
        })
        // Do any additional setup after loading the view, typically from a nib.
    }
    

    【讨论】:

    • 如果能解释为什么 OP 收到错误以及您的代码如何修复错误,这将是一个非常好的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2020-11-23
    相关资源
    最近更新 更多