Karolizzz
Karolizzz

Reputation: 119

Swift Cannot convert value of type to expected argument type

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

Line }, withCancel: { shows a compiler error:

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

Upvotes: 0

Views: 2384

Answers (1)

torinpitchers
torinpitchers

Reputation: 1292

Try this

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

Upvotes: 0

Related Questions