-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathPropertyItem.swift
More file actions
40 lines (36 loc) · 1.08 KB
/
PropertyItem.swift
File metadata and controls
40 lines (36 loc) · 1.08 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
//
// PropertyItem.swift
// JSONCodable
//
// Created by Richard Fox on 6/19/16.
//
//
import JSONCodable
struct PropertyItem {
let name: String
let long: Double
let lat: Double
let rel: String
let type: String
}
extension PropertyItem: JSONDecodable {
init(object: JSONObject) throws {
let decoder = JSONDecoder(object: object)
rel = try decoder.decode("rel")
type = try decoder.decode("class")
name = try decoder.decode("properties.name")
long = try decoder.decode("properties.location.coord.long")
lat = try decoder.decode("properties.location.coord.lat")
}
}
extension PropertyItem: JSONEncodable {
func toJSON() throws -> Any {
return try JSONEncoder.create { (encoder) -> Void in
try encoder.encode(rel, key: "rel")
try encoder.encode(type, key: "class")
try encoder.encode(name, key: "properties.name")
try encoder.encode(long, key: "properties.location.coord.long")
try encoder.encode(lat, key: "properties.location.coord.lat")
}
}
}