Reputation: 55
This is my firebase. I want to retrieve the names "anaesthesia", "musculoskeletal", "options" into an array and print it out. This is my swift code
ref?.child("mcqbase-159dc").observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists(){
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
self.categoriesArray.append(key)
print(self.categoriesArray)
}
}
})
It returns a blank in my terminal. Can anyone help me?
Upvotes: 0
Views: 28
Reputation: 1158
"anaesthesia", "musculoskeletal" and other your database table's names. You can change your structure to :
And your snapshot code must be :
Database.database().reference().child("names").observeSingleEvent(of: .value) { (snapshot) in
//Your code
}
Upvotes: 1