So I import PromiseKit and then try
FIRDatabase.database().reference().child("somechild").removeValue().then {
/////
}
Obviously, this doesn't work and I was wondering what am I missing to make promises work with Firebase, if its even possible. What I'm trying to accomplish is to remove four Firebase references all at once with a single catch method.
With nodeJs I would easily use:
Promise.all ([
someRef.remove(),
someRef.remove(),
someRef.remove(),
someRef.remove()
]).then (function({
}).catch({
//handle error
})
Is there a way to accomplish this in Swift at all?
you can wrap Firebase function with fulfill and reject
/// Get chat IDs of user conversations
///
/// - Returns: array of user chat IDs
private func getUserChatIds() -> Promise<[String]> {
return Promise { fulfill, reject in
let userChatIDsRef = Database.database().reference()
.child(FireDatabasePaths.UserInfoPath.rawValue)
.child(userID).child("chatIDs")
userChatIDsRef.observe(.childAdded, with: { snapshot in
if let chatIDdic = snapshot.value as? [String: AnyObject] {
let keys = Array(chatIDdic.keys)
fulfill(keys)
} else {
reject(FirebaseError.empty)
}
})
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With