Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase completion listeners in swift

How do you execute a completion listener for firebase in swift? It says there are completion listers for SetValue and UpdateValue in the docs but there is no example.

like image 972
Sean Cook Avatar asked Feb 23 '26 21:02

Sean Cook


1 Answers

The completion of a setValue is handled within the {} block (closure). So once the attempt to setValue is made, the code within that block executes. error will be nil if none and snapshot will be the data that was written.

let ref = self.myRootRef.child("some_path")
    ref.setValue("Hello", withCompletionBlock: { (error, snapshot) in
        if error != nil {
            print("oops, an error")
        } else {
            print("completed")
        }
    })

gives a result of

root_ref
   some_path: Hello

and prints "completed"

like image 166
Jay Avatar answered Feb 25 '26 18:02

Jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!