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.
For setValue in Firebase you can write completion blocks as below:
let ref = Database.database().reference().child("somepath")
ref.setValue("value") { (error, databaseRef) in
if error != nil {
print("Error for setting value")
} else {
print("Value set successfully.")
}
}
For updateValue in Firebase:
let newKeyValueData:[String:Any] = ["key1":"value1", "key2":value2] as [String:Any]
ref.updateChildValues(["someKey":"value"]) { (error, dbRef) in
if error != nil {
print("Error for updating value")
} else {
print("Value updated successfully.")
}
}