2016-09-29 61 views
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 in 
    print(error.description) 
    }) 
    // Do any additional setup after loading the view, typically from a nib. 
} 

}, withCancel: {行显示一个编译器错误:斯威夫特无法将类型的价值预期参数类型

cannot convert value of type '(_) ->()' to expected argument type '((Error) -> Void)'

回答

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

如果有这将是一个很好的答案解释OP为什么会收到错误以及您的代码如何解决错误。 – Jim

相关问题