I am new to Firebase and I am trying to get the children from a DataSnapshot and add the keys to a list. But I am getting an error. Am i not unwrapping the data correctly or what am i doing wrong?
var arr: Array<String> = []
override func viewDidLoad() {
super.viewDidLoad()
populateArray()
print(arr)
func populateArray(){
ref.child("Sept24 - Oct 24").observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.childrenCount)
let enumerator = snapshot.children
while let rest = enumerator.nextObject() as? DataSnapshot {
//print(rest.key)
self.arr.append(rest.key)
}
DispatchQueue.main.async{
self.sideMenuTable.reloadData()
}
})
print(arr)
}
arr is a global array with type string and i am calling populateArray() in the viewDidLoad() function.