Skip to content

Instantly share code, notes, and snippets.

@bartjacobs
Created June 1, 2017 12:33
Show Gist options
  • Save bartjacobs/1e53e9abd1ab46175141c9786d1e9e03 to your computer and use it in GitHub Desktop.
Save bartjacobs/1e53e9abd1ab46175141c9786d1e9e03 to your computer and use it in GitHub Desktop.
import Foundation
struct WeatherDayData {
let time: Date
let icon: String
let windSpeed: Double?
let temperatureMin: Double
let temperatureMax: Double
}
extension WeatherDayData: JSONDecodable {
init(decoder: JSONDecoder) throws {
self.icon = try decoder.decode(key: "icon")
self.windSpeed = try? decoder.decode(key: "windSpeed")
self.temperatureMin = try decoder.decode(key: "temperatureMin")
self.temperatureMax = try decoder.decode(key: "temperatureMax")
let time: Double = try decoder.decode(key: "time")
self.time = Date(timeIntervalSince1970: time)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment