Displaying Weather data on the Restaurant Detail screen
-
You have configured the Let’s Eat app by registering its App ID and adding the WeatherKit capability to it, and you have created the
WeatherDataManager
class to fetch the weather from a specified location. Now, you will modify theRestaurantDetailViewController
class to display weather information for a restaurant on the Restaurant Detail screen. Follow these steps:
- Click the
RestaurantDetailViewController
file in the Project navigator. Add a new property to hold an instance ofWeatherDataManager()
after theselectedRestaurant
property:var selectedRestaurant: RestaurantItem? let weatherDataManager = WeatherDataManager()
- Add the following code to the
private
extension after theinitialize()
method to implement thedisplayWeather
method:func displayWeather() { Task { if let lat = selectedRestaurant?.lat, let long = selectedRestaurant?.long { ...