From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Completing the OpenWeatherMap controller

Completing the OpenWeatherMap controller

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Completing the OpenWeatherMap controller

- Let's continue the implementation of the OpenWeatherMap controller. For networking, we'll use a URL dataTask. Let dataTask, and I'm going to use the URL sessions initializer that takes a URL and the completionHandler. For URL, I provide endpointURL, and we're going to implement the completionHandler. We have a data parameter, a response, and an error. If there is an error, we're going to wrap it in our dedicated error type and pass it back to the caller. So, let's check whether there was an error. It should be nil, or else we call our completionHandler. I'm using guard to check if it's nil, and if it's not nil, we invoke the completionHandler. I provide nil for the weather information and webServiceControllerError forwarded, and I include the error. And exit the method call. The return response shouldn't be nil either, otherwise, I invoke the completionHandler and provide the invalidPayload error. Guard let responseData…

Contents