So, in my code, you can see that I want to return the information that I retrieve from Firebase, but always the method returns an empty array, I'm new to Swift, can you please explain why this is happening and how can I make it work? Thanks a lot.
var catalog:[String:NSDictionary] = [String():NSDictionary()]
func readCatalogInfo()->[String:NSDictionary]{
let ref = Database.database(url: "https://reforestar-database-default-rtdb.europe-west1.firebasedatabase.app/").reference()
_ = ref.child("trees").observe(.value, with: {snapshot in
guard let information:[String:NSDictionary] = snapshot.value as? [String:NSDictionary] else {
print("Error in getting information about the Trees")
return
}
self.catalog = information
})
return self.catalog
}