O'Reilly logo

Swift 2 By Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving the actual forecast

We have almost completed the app, but it is still missing the most important part: the weather forecast.

Getting the forecast from OpenWeatherMap

There are plenty of services that provide forecasts for free or for a small amount of money.

For our app, we'll use http://openweathermap.org, whose API is free for a small number of calls.

First of all, we create the WeatherCondition struct to handle the forecast:

import Foundation struct WeatherCondition { let cityName: String? let weather: String let icon: IconType? let time: NSDate let tempKelvin: Double let maxTempKelvin: Double let minTempKelvin: Double var tempFahrenheit: Double { get { return tempCelsius * 9.0/5.0 + 32.0 } } var maxTempFahrenheit: Double { get { return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required