Skip to content

Commit 6ca1b86

Browse files
committed
Naming conventions
1 parent ce52295 commit 6ca1b86

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

MapboxGeocoder/MBPlacemark.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ open class Placemark: NSObject, Codable {
7171
case address
7272
case qualifiedName = "place_name"
7373
case superiorPlacemarks = "context"
74-
case center
74+
case centerCoordinate = "center"
7575
case code = "short_code"
7676
case wikidataItemIdentifier = "wikidata"
7777
case properties
@@ -89,8 +89,9 @@ open class Placemark: NSObject, Codable {
8989
qualifiedName = try container.decodeIfPresent(String.self, forKey: .qualifiedName)
9090
superiorPlacemarks = try container.decodeIfPresent([GeocodedPlacemark].self, forKey: .superiorPlacemarks)
9191

92-
if let center = try container.decodeIfPresent([CLLocationDegrees].self, forKey: .center) {
93-
location = CLLocation(latitude: center.last!, longitude: center.first!)
92+
if let coordinates = try container.decodeIfPresent([CLLocationDegrees].self, forKey: .centerCoordinate) {
93+
let coordinate = CLLocationCoordinate2D(geoJSON: coordinates)
94+
location = CLLocation(coordinate: coordinate)
9495
}
9596

9697
code = try container.decodeIfPresent(String.self, forKey: .code)?.uppercased()
@@ -115,13 +116,12 @@ open class Placemark: NSObject, Codable {
115116
try container.encode(address, forKey: .address)
116117
try container.encode(qualifiedName, forKey: .qualifiedName)
117118
try container.encode(superiorPlacemarks, forKey: .superiorPlacemarks)
118-
if let location = location {
119-
try container.encode([location.coordinate.longitude, location.coordinate.latitude], forKey: .center)
120-
}
121-
122119
try container.encode(code, forKey: .code)
123120
try container.encode(wikidataItemIdentifier, forKey: .wikidataItemIdentifier)
124121
try container.encode(properties, forKey: .properties)
122+
if let location = location {
123+
try container.encode([location.coordinate.longitude, location.coordinate.latitude], forKey: .centerCoordinate)
124+
}
125125
}
126126

127127
@objc open override var hashValue: Int {
@@ -148,6 +148,9 @@ open class Placemark: NSObject, Codable {
148148
*/
149149
fileprivate var identifier: String
150150

151+
/**
152+
A subset of the `properties` object on a GeoJSON feature suited for Geocoding results.
153+
*/
151154
fileprivate var properties: Properties?
152155

153156
/**
@@ -363,8 +366,7 @@ internal struct GeocodeResult: Codable {
363366
}
364367

365368
/**
366-
`Properties` represents a concrete subset of the `properties` object
367-
on a GeoJSON feature suited for Geocoding results.
369+
A subset of the `properties` object on a GeoJSON feature suited for Geocoding results.
368370
*/
369371
internal struct Properties: Codable {
370372
private enum CodingKeys: String, CodingKey {
@@ -404,7 +406,7 @@ open class GeocodedPlacemark: Placemark {
404406
get {
405407
let text = super.name
406408
// For address features, `text` is just the street name. Look through the fully-qualified address to determine whether to put the house number before or after the street name.
407-
if let houseNumber = self.address, scope == .address {
409+
if let houseNumber = properties?.address, scope == .address {
408410
let streetName = text
409411
let reversedAddress = "\(streetName) \(houseNumber)"
410412
if qualifiedNameComponents.contains(reversedAddress) {

0 commit comments

Comments
 (0)