Creating the WeatherDataManager class
Your app now has an App ID that has been registered with the Apple Weather Service, and you have added the WeatherKit capability to it. Now you will create a new class, WeatherDataManager, that will fetch the current weather at a particular restaurant’s location. Follow these steps:
- Right-click on the
Miscfolder and select New File. - iOS should already be selected. Choose Swift File, then click Next.
- Name the file
WeatherDataManagerand then click Create to display its contents in the Editor area. - Add the following code after the
import Foundationstatement:import WeatherKit import CoreLocation struct WeatherDataManager { private let weatherService = WeatherService() func fetchWeather(at restaurantLocation: CLLocation) async -> (String, String) { let weather = try? await weatherService.weather( for: restaurantLocation) if let weather = weather { let temperature...