Hi,
So I am using this function getListAtFIRStore()
which is fetching data from firestore and returning it. But the fetching takes some time and before that happens the function already returns back the array which is empty at that moment.
How do I wait for the fetching task to be completed before the function returns the array back?
class CheckForDownloads {
var userName = String()
func refreshResources(forUser username: String) {
self.userName = username
let listOfImagesAtFirestore = getListAtFIRStore()
print(listOfImagesAtFirestore)
}
func getListAtFIRStore() -> [String]{
let root = Storage.storage().reference()
var str3 = [String]()
root.child("MagicFrame/\(userName)/images").listAll { (result, error) in
if let error = error {
print("Error in fetching list from firestore \(error.localizedDescription)")
}else{
for item in result.items{
if let str1 = (item.description.components(separatedBy: ["/"]).last) {
if let str2 = (str1.components(separatedBy: ["."])).first{
print(str2)
str3.append(str2)
}
}
}
}
}
return str3
}
}