Skip to content

Commit e668e4f

Browse files
committed
Fixed landmark roundtripping
1 parent 7cae0f4 commit e668e4f

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

MapboxGeocoder/MBPlacemark.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ public class Placemark: NSObject, NSCopying, NSSecureCoding {
161161
The scope offers a general indication of the size or importance of the feature represented by the placemark – in other words, how local the feature is.
162162
*/
163163
public var scope: PlacemarkScope {
164-
let components = identifier.characters.split(".")
165-
assert(components.count == 2)
166-
let scopeCharacters = identifier.characters.split(".").first!
167-
return PlacemarkScope(descriptions: [String(scopeCharacters)])
164+
let components = identifier.componentsSeparatedByString(".")
165+
assert(components.count > 0)
166+
return PlacemarkScope(descriptions: [components.prefix(2).joinWithSeparator(".")]) ?? PlacemarkScope(descriptions: [components.first!]) ?? []
168167
}
169168

170169
/**

MapboxGeocoder/MBPlacemarkScope.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension PlacemarkScope: CustomStringConvertible {
44
/**
55
Initializes a placemark scope bitmask corresponding to the given array of string representations of scopes.
66
*/
7-
public init(descriptions: [String]) {
7+
public init?(descriptions: [String]) {
88
var scope: PlacemarkScope = []
99
for description in descriptions {
1010
switch description {
@@ -24,12 +24,13 @@ extension PlacemarkScope: CustomStringConvertible {
2424
scope.insert(.Neighborhood)
2525
case "address":
2626
scope.insert(.Address)
27-
case "poi":
28-
scope.insert(.PointOfInterest)
27+
2928
case "poi.landmark":
3029
scope.insert(.Landmark)
30+
case "poi":
31+
scope.insert(.PointOfInterest)
3132
default:
32-
break
33+
return nil
3334
}
3435
}
3536
self.init(rawValue: scope.rawValue)
@@ -61,11 +62,11 @@ extension PlacemarkScope: CustomStringConvertible {
6162
if contains(.Address) {
6263
descriptions.append("address")
6364
}
64-
if contains(.PointOfInterest) {
65-
descriptions.append("poi")
66-
}
65+
6766
if contains(.Landmark) {
6867
descriptions.append("poi.landmark")
68+
} else if contains(.PointOfInterest) {
69+
descriptions.append("poi")
6970
}
7071
return descriptions.joinWithSeparator(",")
7172
}

MapboxGeocoderTests/ForwardGeocodingTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ class ForwardGeocodingTests: XCTestCase {
8181
options.allowedScopes = [.Region, .Place, .Locality, .PointOfInterest]
8282
options.allowedISOCountryCodes = ["NC"]
8383
let task = geocoder.geocode(options: options) { (placemarks, attribution, error) in
84-
XCTAssertEqual(placemarks?.count, 0, "forward geocode should return no results for invalid query")
85-
86-
XCTAssertEqual(attribution, "NOTICE: © 2016 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained.")
84+
XCTAssertNil(placemarks?.count, "forward geocode should return no results for invalid query")
85+
XCTAssertNil(attribution)
8786

8887
expection.fulfill()
8988
}

0 commit comments

Comments
 (0)