Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetValue Completion Block with Firebase 3.x

In Firebase 2.5.1, this was working:

let post1Ref = sendRequestRef.childByAutoId()
post1Ref.setValue(request, withCompletionBlock: {( error:NSError?, ref:Firebase!) in

})

However, I couldn't figure out how to achieve it in 3.x (as the docs for completion doesn't really tell it)

let post1Ref = sendRequestRef.childByAutoId()
post1Ref.setValue(request, withCompletionBlock: {( error:NSError?, ref:Firebase!) in
    if (error != nil) {
       print("ERROR")
    } else {
       print("Success")
    }
})

This throws an error:

Use of unresolved Firebase

What is the proper way of handling completion block with Firebase 3.x?

like image 582
senty Avatar asked Jun 13 '16 09:06

senty


1 Answers

Use

ref.setValue(object) { (error, ref) -> Void in

}

Here ref is FIRDatabaseReference

like image 165
Shubhank Avatar answered Nov 02 '22 14:11

Shubhank