7

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?

senty
  • 12,385
  • 28
  • 130
  • 260

1 Answers1

26

Use

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

}

Here ref is FIRDatabaseReference

Shubhank
  • 21,721
  • 8
  • 65
  • 83