SetValue Completion Block with Firebase 3.x
Asked Answered
B

1

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?

Bothy answered 13/6, 2016 at 9:19 Comment(1)
firebase.google.com/docs/database/ios/save-dataElohist
R
26

Use

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

}

Here ref is FIRDatabaseReference

Romance answered 13/6, 2016 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.