2016-09-29 64 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

相關問題