summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-07-08 19:07:13 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-07-12 14:27:57 +0200
commit69bb5d41f6bd07462583d34781ee400795e6d0f2 (patch)
tree928cf5f245fc6ab2c2b2703fb739c35196859222
parent18f05d0bc25c9b314bd7c002c8c8c794bf15ff19 (diff)
downloadmullvadvpn-69bb5d41f6bd07462583d34781ee400795e6d0f2.tar.xz
mullvadvpn-69bb5d41f6bd07462583d34781ee400795e6d0f2.zip
Drop parsing unused fields from geojson
-rw-r--r--ios/MullvadVPN/GeoJSON.swift65
1 files changed, 11 insertions, 54 deletions
diff --git a/ios/MullvadVPN/GeoJSON.swift b/ios/MullvadVPN/GeoJSON.swift
index 623ab01257..ab1b21aacc 100644
--- a/ios/MullvadVPN/GeoJSON.swift
+++ b/ios/MullvadVPN/GeoJSON.swift
@@ -23,7 +23,11 @@ extension GeoJSON {
if type == "FeatureCollection" {
features = try container.decode([Feature].self, forKey: .features)
} else {
- throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "FeatureCollection: Invalid type \(type)")
+ throw DecodingError.dataCorruptedError(
+ forKey: .type,
+ in: container,
+ debugDescription: "FeatureCollection: Invalid type \(type)"
+ )
}
}
@@ -47,72 +51,25 @@ extension GeoJSON {
}
}
- fileprivate enum AnyDecodableValue: Decodable {
- case boolean(Bool)
- case number(Int64)
- case string(String)
- case dictionary([String: AnyDecodableValue])
- case array([AnyDecodableValue])
- case `nil`
-
- init(from decoder: Decoder) throws {
- let container = try decoder.singleValueContainer()
-
- if container.decodeNil() {
- self = .nil
- } else if let value = try? container.decode(Bool.self) {
- self = .boolean(value)
- } else if let value = try? container.decode(Int64.self) {
- self = .number(value)
- } else if let value = try? container.decode(String.self) {
- self = .string(value)
- } else if let value = try? container.decode([String: AnyDecodableValue].self) {
- self = .dictionary(value)
- } else if let value = try? container.decode([AnyDecodableValue].self) {
- self = .array(value)
- } else {
- throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unknown value type")
- }
- }
-
- var anyValue: Any? {
- switch self {
- case .boolean(let value):
- return value
- case .number(let value):
- return value
- case .string(let value):
- return value
- case .dictionary(let value):
- return value.mapValues { $0.anyValue }
- case .array(let value):
- return value.map { $0.anyValue }
- case .nil:
- return nil
- }
- }
- }
-
struct Feature: Decodable {
- let identifier: String?
let geometry: Geometry?
- let properties: [String: Any?]?
private enum CodingKeys: String, CodingKey {
- case identifier = "id", properties, type, geometry
+ case type, geometry
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(String.self, forKey: .type)
- identifier = try container.decodeIfPresent(String.self, forKey: .identifier)
- properties = try container.decodeIfPresent(AnyDecodableValue.self, forKey: .properties)?.anyValue as? [String: Any?]
-
if type == "Feature" {
geometry = try container.decodeIfPresent(Geometry.self, forKey: .geometry)
} else {
- throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Feature: Invalid type \(type)")
+ throw DecodingError.dataCorruptedError(
+ forKey: .type,
+ in: container,
+ debugDescription: "Feature: Invalid type \(type)"
+ )
}
}
}