I do a firebase query to get a list of ids. In the next step I want to do another query for each id to get the name of the id and show it in a tableView Cell.
I try to store them into an array. But everytime I print the array its empty.
func loadDataFromFirebase() {
databaseRef.child("user/...").observe(.value) { (snapshot) in
self.keys.removeAll()
if let snapshotValue = snapshot.value as? [String: [String: Any]] {
for (key, value) in snapshotValue {
if let like = value["like"], like as! String == "true" {
self.keys.append(key)
}
}
}
self.keys.forEach { variableNew in
var connect = moreInfoWithPlaceId()
var namesArray: [String] = []
connect.fetchPoi(placeId: variableNew) {
if let info = moreInfoWithPlaceId.infoWithPlaceId.first(where: { $0.place_id == variableNew }) {
namesArray.append(info.name)
}
if let info = moreInfoWithPlaceId.infoWithPlaceId.first(where: { $0.place_id == variableNew }) {
namesArray.append(info.name)
}
}
print(namesArray)
}
self.tableView.reloadData()
}
}