I need to get all the data from a specific table but their are times that the table does not exist in firebase. And I want to know if the reason is the table doesn't exist.
I'm using observe(.childAdded) btw.
I need to get all the data from a specific table but their are times that the table does not exist in firebase. And I want to know if the reason is the table doesn't exist.
I'm using observe(.childAdded) btw.
Try this if this will work
let ref = Database.database().reference()
ref.observeSingleEvent(of: .value) { (snapshot) in
if snapshot.hasChild("mytable") {
// exist
} else {
// does not exist
}
}
While Elbert's answer works, it downloads more data than needed. It downloads your entire database, to check if one node exists.
I recommend instead to only read the node that you're checking:
let ref = Database.database().reference()
ref.child("mytable").observeSingleEvent(of: .value) { (snapshot) in
if snapshot.exists() {
// exists
} else {
// does not exist
}
}
Also see: