Posts

Post marked as solved
5 Replies
328 Views
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     }      }
Posted
by Hussey.
Last updated
.
Post not yet marked as solved
1 Replies
152 Views
Hi folks, I am downloading some images from Firebase and adding them to main bundle resources, after which I use them. I am having trouble with making my code to wait for the downloads to get complete before it executes the next statement. I tried completion handlers, async/await but still the same. Not sure if I am doing it the right way. Can anyone help what is the correct approach for this scenario. override func viewWillAppear(_ animated: Bool) {         super.viewWillAppear(animated)         // Create a session configuration          let configuration = ARImageTrackingConfiguration()             Task{                 await self.checkForDownloads.refreshResources(forUser: self.username)             }             if let trackedImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: Bundle.main){                 configuration.trackingImages = trackedImages                 configuration.maximumNumberOfTrackedImages = 1                 print("Images Found: \(trackedImages.count)")             }         sceneView.session.run(configuration)     }     func refreshResources(forUser username: String) async { //.. } I am expecting checkForDownloads.refreshResources to finish downloading first, then proceed to next statement.
Posted
by Hussey.
Last updated
.