How does async/await work?

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.

All the code you want to execute after refreshResources should be inside the Task block.

How does async/await work?
 
 
Q