Reputation: 33
I'm trying to get a String array with the list of all usernames, but for some reason my code isn't working. Output should be [sean, yuh]
Database.database().reference().child("usernames").observeSingleEvent(of: .value, with: { (snapshot : DataSnapshot) in
for child in snapshot.children {
let snap = child as! DataSnapshot
let uid = snap.childSnapshot(forPath: "username")
self.array.append(uid1)
}
}
Upvotes: 0
Views: 41
Reputation: 598728
Your uid1
is not declared in the code you shared, and definitely not the value of the username property in the JSON. In addition, you'll want to get the value
of the child snapshot. So combines:
Database.database().reference().child("usernames").observeSingleEvent(of: .value, with: { (snapshot : DataSnapshot) in
for child in snapshot.children {
let snap = child as! DataSnapshot
let uid = snap.childSnapshot(forPath: "username")
self.array.append(uid.value)
}
}
Upvotes: 1