Just make an array of snapshot with keys and loop through it just like that if you want keys of "vets":
let ref = Database.database().reference().child("vets")
ref.observe(.childAdded) { (snapshot) in
for key in [snapshot.key] {
print(key)
}
}
However, if you want the keys of "vets" children then you can do it like this:
ref.observe(.childAdded) { (snapshot) in
guard let snapChildren = snapshot.value as? [String: Any] else { return }
for (key, value) in snapChildren {
print(key)
}
}
If you need all key-value pairs of "vets" you may get them like this:
ref.observe(.childAdded) { (snapshot) in
guard let snapChildren = snapshot.value as? [String: Any] else { return }
for snap in snapChildren {
print(snap)
}
}
Wanna print value for a certain key of vets children? Let's say you want to print a vet name:
ref.observe(.childAdded) { (snapshot) in
guard let snapChildren = snapshot.value as? [String: Any] else { return }
for (key, value) in snapChildren {
if key == "Name" {
print(value)
}
}
}
Note:
This code will work assuming your path is Database.database().reference().child("vets") and that each vet entry has some kind of AutoID or UID which is our snapshot.key in the first example.