Skip to content

Commit 81ba38b

Browse files
authored
Don't reverse geocode during encoding (#413)
1 parent 23d1a07 commit 81ba38b

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Sources/TripKit/model/TKNamedCoordinate.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ open class TKNamedCoordinate : NSObject, NSSecureCoding, Codable, TKClusterable
212212
try container.encode(coordinate.latitude, forKey: .latitude)
213213
try container.encode(coordinate.longitude, forKey: .longitude)
214214
try container.encode(name, forKey: .name)
215-
try container.encode(address, forKey: .address)
216215
try container.encode(locationID, forKey: .locationID)
217216
try container.encode(timeZoneID, forKey: .timeZoneID)
218217
try container.encode(clusterIdentifier, forKey: .clusterIdentifier)
@@ -221,6 +220,9 @@ open class TKNamedCoordinate : NSObject, NSSecureCoding, Codable, TKClusterable
221220
try container.encode(isDraggable, forKey: .isDraggable)
222221
try container.encode(isSuburb, forKey: .isSuburb)
223222

223+
// Important to encode the underlying value to not trigger reverse-geocoding.
224+
try container.encode(_address, forKey: .address)
225+
224226
if let sanitized = TKJSONSanitizer.sanitize(data) {
225227
let encodedData = try JSONSerialization.data(withJSONObject: sanitized, options: [])
226228
try container.encode(encodedData, forKey: .data)
@@ -262,13 +264,16 @@ open class TKNamedCoordinate : NSObject, NSSecureCoding, Codable, TKClusterable
262264
}
263265
coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
264266
name = aDecoder.decodeObject(of: NSString.self, forKey: "name") as String?
265-
_address = aDecoder.decodeObject(of: NSString.self, forKey: "address") as String?
266267
locationID = aDecoder.decodeObject(of: NSString.self, forKey: "locationID") as String?
267268
timeZoneID = aDecoder.decodeObject(of: NSString.self, forKey: "timeZone") as String?
268269
clusterIdentifier = aDecoder.decodeObject(of: NSString.self, forKey: "clusterIdentifier") as String?
269270
modeIdentifiers = aDecoder.decodeObject(of: [NSString.self, NSArray.self], forKey: "modeIdentifiers") as? [String]
270271
klass = aDecoder.decodeObject(of: NSString.self, forKey: "klass") as String?
272+
273+
// Important to encode the underlying value to not trigger reverse-geocoding.
274+
_address = aDecoder.decodeObject(of: NSString.self, forKey: "address") as String?
271275
_placemark = aDecoder.decodeObject(of: CLPlacemark.self, forKey: "placemark")
276+
272277
isDraggable = aDecoder.decodeBool(forKey: "isDraggable")
273278
isSuburb = aDecoder.decodeBool(forKey: "isSuburb")
274279
data = aDecoder.decodeObject(of: [
@@ -285,16 +290,18 @@ open class TKNamedCoordinate : NSObject, NSSecureCoding, Codable, TKClusterable
285290
aCoder.encode(coordinate.latitude, forKey: "latitude")
286291
aCoder.encode(coordinate.longitude, forKey: "longitude")
287292
aCoder.encode(name, forKey: "name")
288-
aCoder.encode(address, forKey: "address")
289293
aCoder.encode(locationID, forKey: "locationID")
290294
aCoder.encode(timeZoneID, forKey: "timeZone")
291295
aCoder.encode(clusterIdentifier, forKey: "clusterIdentifier")
292296
aCoder.encode(modeIdentifiers, forKey: "modeIdentifiers")
293297
aCoder.encode(klass, forKey: "klass")
294-
aCoder.encode(_placemark, forKey: "placemark")
295298
aCoder.encode(isDraggable, forKey: "isDraggable")
296299
aCoder.encode(isSuburb, forKey: "isSuburb")
297300
aCoder.encode(data, forKey: "data")
301+
302+
// Important to encode the underlying value to not trigger reverse-geocoding.
303+
aCoder.encode(_address, forKey: "address")
304+
aCoder.encode(_placemark, forKey: "placemark")
298305
}
299306

300307
}

0 commit comments

Comments
 (0)