Updating RestaurantListViewController to use async/await
When you run your Let's Eat app, you may notice a delay when the Restaurant List screen is displaying a list of restaurants. This is because the code used to download restaurant images is not asynchronous, and the app is not able to do other work while restaurant images are being downloaded.
The code that downloads the restaurant image data and converts it into an image is inside the collectionView(_:cellForItemAt:)
method in the RestaurantListViewController
class definition. You'll modify this code so that it is performed asynchronously.
Open your LetsEat
project that you modified in Chapter 22, Getting Started with Mac Catalyst, and open the RestaurantListViewController
file (inside the Restaurants
folder) in the Project navigator. Update the collectionView(_:cellForItemAt:)
method as shown below:
if let imageURL = restaurantItem.imageURL { Task { ...