I\'m trying to loop through children in my Firebase Database to retrieve a nested key.
My database is structured like this:
\"Users\" : {
\"Username\" :
The problem in your code is that snapshot
refers to the Favorites node – instead of looking for LocationName there, you should look for it inside each of the Location child nodes. Therefore your loop should look something like this:
let databaseHandle = databaseRef.observe(.value, with: { snapshot in
for child in snapshot.children {
let childSnapshot = snapshot.childSnapshotForPath(child.key)
if let dbLocation = childSnapshot.value["LocationName"] as? String {
print(dbLocation)
}
}
})