Implementing asynchronous images in SwiftUI
Imagine an e-commerce app or a hotel booking app.
All the content is on the server, and the app must download it and present it smoothly, taking care of the possible delay, lag, error, and so on. An essential part of this content is images. We could download and synchronously present images, but that would mean blocking the UI waiting for the download, making the app clunky and unpleasant to use.
That said, implementing images that asynchronously download and present themselves is a valuable tool to have in our toolbox.
In this recipe, we are going to implement an
AsyncImage component that you can reuse in your apps whenever you need this feature.
No external resources are needed in this recipe, so just create a SwiftUI project in Xcode called
How to do it
Two ingredients make the recipe: an