-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrentWeather.swift
46 lines (38 loc) · 1.24 KB
/
CurrentWeather.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// CurrentWeather.swift
// MySunnies
//
// Created by Justin Ji on 29/06/2017.
// Copyright © 2017 Justin Ji. All rights reserved.
//
import Foundation
struct CurrentWeather {
let temperature: Double
let humidity: Double
let precipitationProbability: Double
let summary: String
let icon: String
}
extension CurrentWeather {
struct Key {
static let temperature = "temperature"
static let humidity = "humidity"
static let precipitationProbability = "precipProbability"
static let summary = "summary"
static let icon = "icon"
}
//This initialiser is going to accept a dictionary of type string any object
init?(json: [String: AnyObject]) {
//This initialiser takes the JSON weather data and covert it into double and string types
guard let temValue = json[Key.temperature] as? Double,
let humidityValue = json[Key.humidity] as? Double,
let precipitationProbabilityValue = json[Key.precipitationProbability] as? Double,
let summaryString = json[Key.summary] as? String,
let iconString = json[Key.icon] as? String else { return nil}
self.temperature = temValue
self.humidity = humidityValue
self.precipitationProbability = precipitationProbabilityValue
self.summary = summaryString
self.icon = iconString
}
}