Swift无法将类型的值转换为预期的参数类型

时间:2016-09-29 10:18:01

标签: swift xcode

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: {显示编译器错误:

  

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

1 个答案:

答案 0 :(得分:0)

试试这个

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.
}