-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlace.swift
More file actions
executable file
·256 lines (230 loc) · 13.8 KB
/
Place.swift
File metadata and controls
executable file
·256 lines (230 loc) · 13.8 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// Place.swift
// Atmos
//
// Created by Evangelos on 02/01/16.
// Copyright © 2016 Evangelos. All rights reserved.
//
import UIKit
public class Place: NSObject, NSCoding {
//MARK Properties
private var name: String
private var country: String
private var timestamp: String
private var crowdReport: CrowdReport
private var crowdPrediction: CrowdPrediction
private var position: Position
//MARK: Archiving Paths
//Creating a file path to data saved in a persistent way
static let DocumentsDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
static let ArchiveURL = DocumentsDirectory.URLByAppendingPathComponent("places")
//MARK: Types
struct PropertyKey {
static let nameKey = "name"
static let countryKey = "country"
static let timestampKey = "timestamp"
//MARK: CrowdReport Property Keys
static let crIdKey = "crId"
static let crTypeKey="crType"
static let crTemperatureKey = "crTemperature"
static let crWeatherKey = "crWeather"
static let crWindKey = "crWind"
static let crHumidityKey = "crHumidity"
static let crWeatherIconKey = "crWeatherIcon"
static let crWindIconKey = "crWindIcon"
static let crPoolKey = "crPool"
static let crTimestampKey = "crTimestamp"
static let crTimeZoneKey = "crTimeZone"
static let crFeelTextKey = "crFeelText"
static let crHumidityTextKey = "crHumidityText"
static let crProgressVisibleKey = "crProgressVisible"
//MARK: CrowdPrediction Property Keys
static let cpIdKey = "cpId"
static let cpTypeKey="cpType"
static let cpTemperatureKey = "cpTemperature"
static let cpWeatherKey = "cpWeather"
static let cpWindKey = "cpWind"
static let cpHumidityKey = "cpHumidity"
static let cpWeatherIconKey = "cpWeatherIcon"
static let cpWindIconKey = "cpWindIcon"
static let cpPoolKey = "cpPool"
static let cpTimestampKey = "cpTimestamp"
static let cpTimeZoneKey = "cpTimeZone"
static let cpFeelTextKey = "cpFeelText"
static let cpHumidityTextKey = "cpHumidityText"
static let cpProgressVisibleKey = "cpProgressVisible"
//MARK: Position Property Keys
static let addressKey = "address"
static let latitudeKey = "latitude"
static let longitudeKey = "longitude"
static let altitudeKey = "altitude"
static let accuracyKey = "accuracy"
static let localTimeZoneKey = "localTimeZone"
static let localTimestampKey = "localTimestamp"
static let serverTimestampKey = "serverTimestamp"
static let sunriseKey = "sunrise"
static let sunsetKey = "sunset"
}//endPropertyKey
//MARK: Initialization
/*
init(name: String, countryName: String, temperature: Double, crowdNumber: Int, weatherIcon: UIImage?){
self.name = name
self.coutryName = countryName
self.temperature = temperature
self.crowdNumber = crowdNumber
self.weatherIcon = weatherIcon
}//endInitilization()
*/
public func encodeWithCoder(aCoder: NSCoder) {
//MARK: encoding Place's fields
//aCoder.encodeObject(String(name), forKey: PropertyKey.nameKey)
aCoder.encodeObject(name, forKey: PropertyKey.nameKey)
aCoder.encodeObject(country, forKey: PropertyKey.countryKey)
aCoder.encodeObject(timestamp, forKey: PropertyKey.timestampKey)
NSLog("--Encoding Place.name: \(name)")
//MARK: encoding CrowdReport's fields
aCoder.encodeObject(crowdReport.getId(), forKey: PropertyKey.crIdKey)
aCoder.encodeObject(crowdReport.getType(), forKey: PropertyKey.crTypeKey)
aCoder.encodeObject(crowdReport.getTemperature(), forKey: PropertyKey.crTemperatureKey)
aCoder.encodeObject(crowdReport.getWeather(), forKey: PropertyKey.crWeatherKey)
aCoder.encodeObject(crowdReport.getWind(), forKey: PropertyKey.crWindKey)
aCoder.encodeObject(crowdReport.getHumidity(), forKey: PropertyKey.crHumidityKey)
aCoder.encodeObject(crowdReport.getWeatherIcon(), forKey: PropertyKey.crWeatherIconKey)
aCoder.encodeObject(crowdReport.getWindIcon(), forKey: PropertyKey.crWindIconKey)
aCoder.encodeObject(crowdReport.getPool(), forKey: PropertyKey.crPoolKey)
aCoder.encodeObject(crowdReport.getTimestamp(), forKey: PropertyKey.crTimestampKey)
aCoder.encodeObject(crowdReport.getTimeZone(), forKey: PropertyKey.crTimeZoneKey)
aCoder.encodeObject(crowdReport.getFeelText(), forKey: PropertyKey.crFeelTextKey)
aCoder.encodeObject(crowdReport.getHumidityText(), forKey: PropertyKey.crHumidityTextKey)
aCoder.encodeObject(crowdReport.getProgressVisible(), forKey: PropertyKey.crProgressVisibleKey)
//MARK: encoding CrowdPrediction's fields
aCoder.encodeObject(crowdPrediction.getId(), forKey: PropertyKey.cpIdKey)
aCoder.encodeObject(crowdPrediction.getType(), forKey: PropertyKey.cpTypeKey)
aCoder.encodeObject(crowdPrediction.getTemperature(), forKey: PropertyKey.cpTemperatureKey)
aCoder.encodeObject(crowdPrediction.getWeather(), forKey: PropertyKey.cpWeatherKey)
aCoder.encodeObject(crowdPrediction.getWind(), forKey: PropertyKey.cpWindKey)
aCoder.encodeObject(crowdPrediction.getHumidity(), forKey: PropertyKey.cpHumidityKey)
aCoder.encodeObject(crowdPrediction.getWeatherIcon(), forKey: PropertyKey.cpWeatherIconKey)
aCoder.encodeObject(crowdPrediction.getWindIcon(), forKey: PropertyKey.cpWindIconKey)
aCoder.encodeObject(crowdPrediction.getPool(), forKey: PropertyKey.cpPoolKey)
aCoder.encodeObject(crowdPrediction.getTimestamp(), forKey: PropertyKey.cpTimestampKey)
aCoder.encodeObject(crowdPrediction.getTimeZone(), forKey: PropertyKey.cpTimeZoneKey)
aCoder.encodeObject(crowdPrediction.getFeelText(), forKey: PropertyKey.cpFeelTextKey)
aCoder.encodeObject(crowdPrediction.getHumidityText(), forKey: PropertyKey.cpHumidityTextKey)
aCoder.encodeObject(crowdPrediction.getProgressVisible(), forKey: PropertyKey.cpProgressVisibleKey)
//MARK: encoding Position's fields
aCoder.encodeObject(position.getAddress(), forKey: PropertyKey.addressKey)
aCoder.encodeObject(position.getLatitude(), forKey: PropertyKey.latitudeKey)
aCoder.encodeObject(position.getLongitude(), forKey: PropertyKey.longitudeKey)
aCoder.encodeObject(position.getAltitude(), forKey: PropertyKey.altitudeKey)
aCoder.encodeObject(position.getAccuracy(), forKey: PropertyKey.accuracyKey)
aCoder.encodeObject(position.getLocalTimeZone(), forKey: PropertyKey.localTimeZoneKey)
aCoder.encodeObject(position.getLocalTimestamp(), forKey: PropertyKey.localTimestampKey)
aCoder.encodeObject(position.getServerTimestamp(), forKey: PropertyKey.serverTimestampKey)
aCoder.encodeObject(position.getSunriseTime(), forKey: PropertyKey.sunriseKey)
aCoder.encodeObject(position.getSunsetTime(), forKey: PropertyKey.sunsetKey)
}//endEncodeWithCoder()
required convenience public init?(coder aDecoder: NSCoder) {
let name = aDecoder.decodeObjectForKey(PropertyKey.nameKey) as! String
let country = aDecoder.decodeObjectForKey(PropertyKey.countryKey) as! String
let timestamp = aDecoder.decodeObjectForKey(PropertyKey.timestampKey) as! String
//Decoding and assembling crowdReport object
let crId = aDecoder.decodeObjectForKey(PropertyKey.crIdKey) as! String
let crType = aDecoder.decodeObjectForKey(PropertyKey.crTypeKey) as! String
let crTemperature = aDecoder.decodeObjectForKey(PropertyKey.crTemperatureKey) as! String
let crWeather = aDecoder.decodeObjectForKey(PropertyKey.crWeatherKey) as! String
let crWind = aDecoder.decodeObjectForKey(PropertyKey.crWindKey) as! String
let crHumidity = aDecoder.decodeObjectForKey(PropertyKey.crHumidityKey) as! String
let crWeatherIcon = aDecoder.decodeObjectForKey(PropertyKey.crWeatherIconKey) as! UIImage
let crWindIcon = aDecoder.decodeObjectForKey(PropertyKey.crWindIconKey) as! UIImage
let crPool = aDecoder.decodeObjectForKey(PropertyKey.crPoolKey) as! String
let crTimestamp = aDecoder.decodeObjectForKey(PropertyKey.crTimestampKey) as! String
let crTimeZone = aDecoder.decodeObjectForKey(PropertyKey.crTimeZoneKey) as! String
let crFeelText = aDecoder.decodeObjectForKey(PropertyKey.crFeelTextKey) as! String
let crHumidityText = aDecoder.decodeObjectForKey(PropertyKey.crHumidityKey) as! String
let crProgressVisible = aDecoder.decodeObjectForKey(PropertyKey.crProgressVisibleKey) as! Bool
let crowdReport = CrowdReport(id: crId, type: crType, temperature: crTemperature, weather: crWeather, wind: crWind, humidity: crHumidity, weatherIcon: crWeatherIcon, windIcon: crWindIcon, pool: crPool, timestamp: crTimestamp, timeZone: crTimeZone, feelText: crFeelText, humidityText: crHumidityText, progressVisible: crProgressVisible)
//Decoding and assembling crowdPrediction object
let cpId = aDecoder.decodeObjectForKey(PropertyKey.cpIdKey) as! String
let cpType = aDecoder.decodeObjectForKey(PropertyKey.cpTypeKey) as! String
let cpTemperature = aDecoder.decodeObjectForKey(PropertyKey.cpTemperatureKey) as! String
let cpWeather = aDecoder.decodeObjectForKey(PropertyKey.cpWeatherKey) as! String
let cpWind = aDecoder.decodeObjectForKey(PropertyKey.cpWindKey) as! String
let cpHumidity = aDecoder.decodeObjectForKey(PropertyKey.cpHumidityKey) as! String
let cpWeatherIcon = aDecoder.decodeObjectForKey(PropertyKey.cpWeatherIconKey) as! UIImage
let cpWindIcon = aDecoder.decodeObjectForKey(PropertyKey.cpWindIconKey) as! UIImage
let cpPool = aDecoder.decodeObjectForKey(PropertyKey.cpPoolKey) as! String
let cpTimestamp = aDecoder.decodeObjectForKey(PropertyKey.cpTimestampKey) as! String
let cpTimeZone = aDecoder.decodeObjectForKey(PropertyKey.cpTimeZoneKey) as! String
let cpFeelText = aDecoder.decodeObjectForKey(PropertyKey.cpFeelTextKey) as! String
let cpHumidityText = aDecoder.decodeObjectForKey(PropertyKey.cpHumidityKey) as! String
let cpProgressVisible = aDecoder.decodeObjectForKey(PropertyKey.cpProgressVisibleKey) as! Bool
let crowdPrediction = CrowdPrediction(id: cpId, type: cpType, temperature: cpTemperature, weather: cpWeather, wind: cpWind, humidity: cpHumidity, weatherIcon: cpWeatherIcon, windIcon: cpWindIcon, pool: cpPool, timestamp: cpTimestamp, timeZone: cpTimeZone, feelText: cpFeelText, humidityText: cpHumidityText, progressVisible: cpProgressVisible)
//Decoding and assembling Position object
let address = aDecoder.decodeObjectForKey(PropertyKey.addressKey) as! String
let latitude = aDecoder.decodeObjectForKey(PropertyKey.latitudeKey) as! String
let longitude = aDecoder.decodeObjectForKey(PropertyKey.longitudeKey) as! String
let altitude = aDecoder.decodeObjectForKey(PropertyKey.altitudeKey) as! String
let accuracy = aDecoder.decodeObjectForKey(PropertyKey.accuracyKey) as! String
let localTimeZone = aDecoder.decodeObjectForKey(PropertyKey.localTimeZoneKey) as! String
let localTimestamp = aDecoder.decodeObjectForKey(PropertyKey.localTimestampKey) as! String
let serverTimestamp = aDecoder.decodeObjectForKey(PropertyKey.serverTimestampKey) as! String
let sunriseTime = aDecoder.decodeObjectForKey(PropertyKey.sunriseKey) as! String
let sunsetTime = aDecoder.decodeObjectForKey(PropertyKey.sunsetKey) as! String
let position = Position(address: address, region: name, country: country, latitude: latitude, longitude: longitude, altitude: altitude, accuracy: accuracy, localTimestamp: localTimestamp, serverTimestamp: serverTimestamp, localTimeZone: localTimeZone, sunrise: sunriseTime, sunset: sunsetTime)
self.init(name: name, country: country, timestamp: timestamp, crowdReport: crowdReport!, crowdPrediction: crowdPrediction!, position: position!)
}//endRequiredConvenienceInit()
init!(name: String, country: String, timestamp: String, crowdReport: CrowdReport, crowdPrediction: CrowdPrediction, position: Position){
self.name = name
NSLog("Self init with name: \(name)")
self.country = country
self.timestamp = timestamp
self.crowdReport = crowdReport
self.crowdPrediction = crowdPrediction
self.position = position
super.init()
}//endInit?()
override init(){
name = "default"
country = "default"
crowdReport = CrowdReport()
crowdPrediction = CrowdPrediction()
position = Position()
timestamp = "default"
}//endInit()
//MARK: Setters
public func setName(_name: String) {
name = _name
}
public func setCountry(_country: String) {
country = _country
}
public func setTimestamp(_timestamp: String) {
timestamp = _timestamp
}
public func setCrowdReport(_crowdReport: CrowdReport) {
crowdReport = _crowdReport
}
public func setCrowdPrediction(_crowdPrediction: CrowdPrediction) {
crowdPrediction = _crowdPrediction
}
public func setPosition(_position: Position) {
position = _position
}
//MARK: Getters
public func getName() -> String {
return name
}
public func getCountry() -> String {
return country
}
public func getCrowdReport() -> CrowdReport {
return crowdReport
}
public func getCrowdPrediction() -> CrowdPrediction {
return crowdPrediction
}
public func getPosition() -> Position {
return position
}
}//endClassPlace