-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForecast.swift
More file actions
99 lines (74 loc) · 2.35 KB
/
Forecast.swift
File metadata and controls
99 lines (74 loc) · 2.35 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Forecast.swift
// WeatherApp1
//
// Created by Aiman Abdullah Anees on 01/10/16.
// Copyright © 2016 Aiman Abdullah Anees. All rights reserved.
//
import UIKit
import Alamofire
class Forecast {
var _date:String!
var _weatherType:String!
var _highTemp:String!
var _lowTemp: String!
var date:String{
if _date == nil{
_date = ""
}
return _date
}
var weatherType:String{
if _weatherType == nil{
_weatherType = ""
}
return _weatherType
}
var highTemp:String{
if _highTemp == nil{
_highTemp = ""
}
return _highTemp
}
var lowTemp:String{
if _lowTemp == nil{
_lowTemp = ""
}
return _lowTemp
}
init(weatherDict: Dictionary<String, AnyObject>){
//To get min and max temp
if let temp = weatherDict["temp"] as? Dictionary<String, AnyObject>{
if let min = temp["min"] as? Double{
let kelvinToCelcius = min - 273.15
self._lowTemp = "\(kelvinToCelcius)"
}
if let max = temp["max"] as? Double{
let kelvinToCelcius1 = max - 273.15
self._highTemp = "\(kelvinToCelcius1)"
}
}
//To get weather type
if let weather = weatherDict["weather"] as? [Dictionary<String, AnyObject>]{
if let main = weather[0]["main"] as? String{
self._weatherType = main
}
}
//To get date
if let date = weatherDict["dt"] as? Double{
let unixDate = Date(timeIntervalSince1970: date) //To convert unix time stamp to normal date
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full
dateFormatter.dateFormat = "EEEE"
dateFormatter.timeStyle = .none
self._date = unixDate.dayOfWeek()
}
}
}
extension Date {
func dayOfWeek() -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE" //To get full name of the day of week code
return dateFormatter.string(from: self)
}
}