Skip to content

Commit 1b046e6

Browse files
authored
Remove the hashable extension for CLLocationCoordinate2D (#4109)
1 parent 8058f7a commit 1b046e6

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
### Other changes
5252

5353
* When launching the application, any stray files left over from old canceled offline tile downloads are cleaned up automatically to save storage space. ([#4085](https://github.com/mapbox/mapbox-navigation-ios/pull/4085))
54+
* Removed the `Hashable`-conforming extension for `CLLocationCoordinate2D` in `MapboxCoreNavigation` to fix a compiler error in applications that define their own `Hashable` conformance for this type. ([#4109](https://github.com/mapbox/mapbox-navigation-ios/pull/4109))
5455

5556
## v2.7.0
5657

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@
339339
B4319F2F27A35EA8005A706E /* SpriteRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4319F2E27A35EA8005A706E /* SpriteRepository.swift */; };
340340
B44177F82649B08400781319 /* UserLocationStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B44177F72649B08400781319 /* UserLocationStyle.swift */; };
341341
B443A48B27BB0CB8000AF101 /* sprite-info.json in Resources */ = {isa = PBXBuildFile; fileRef = B443A48A27BB0CB8000AF101 /* sprite-info.json */; };
342-
B44E1A802891DD350093743C /* CLLocationCoordinate2D.swift in Sources */ = {isa = PBXBuildFile; fileRef = B44E1A7F2891DD350093743C /* CLLocationCoordinate2D.swift */; };
343342
B456A8C12620C9C300FD86D8 /* MMEEventsManager+Spy.h in Headers */ = {isa = PBXBuildFile; fileRef = B456A8B82620C9C000FD86D8 /* MMEEventsManager+Spy.h */; settings = {ATTRIBUTES = (Public, ); }; };
344343
B456A8D22620C9C700FD86D8 /* MMEEventsManager+Spy.m in Sources */ = {isa = PBXBuildFile; fileRef = B456A8B72620C9C000FD86D8 /* MMEEventsManager+Spy.m */; };
345344
B456A8EC2620D26B00FD86D8 /* LeakTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B456A8EB2620D26A00FD86D8 /* LeakTest.swift */; };
@@ -936,7 +935,6 @@
936935
B4319F2E27A35EA8005A706E /* SpriteRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteRepository.swift; sourceTree = "<group>"; };
937936
B44177F72649B08400781319 /* UserLocationStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserLocationStyle.swift; sourceTree = "<group>"; };
938937
B443A48A27BB0CB8000AF101 /* sprite-info.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "sprite-info.json"; sourceTree = "<group>"; };
939-
B44E1A7F2891DD350093743C /* CLLocationCoordinate2D.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLLocationCoordinate2D.swift; sourceTree = "<group>"; };
940938
B456A8B72620C9C000FD86D8 /* MMEEventsManager+Spy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "MMEEventsManager+Spy.m"; path = "include/MMEEventsManager+Spy.m"; sourceTree = "<group>"; };
941939
B456A8B82620C9C000FD86D8 /* MMEEventsManager+Spy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "MMEEventsManager+Spy.h"; path = "include/MMEEventsManager+Spy.h"; sourceTree = "<group>"; };
942940
B456A8EB2620D26A00FD86D8 /* LeakTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeakTest.swift; sourceTree = "<group>"; };
@@ -1970,7 +1968,6 @@
19701968
3A8187C824BDAE9C00708F19 /* URLSession.swift */,
19711969
11D1F89F2696048D0053A93F /* Dictionary+DeepMerge.swift */,
19721970
8AC85EA328628E4F003F8FC8 /* UIDevice.swift */,
1973-
B44E1A7F2891DD350093743C /* CLLocationCoordinate2D.swift */,
19741971
);
19751972
name = Extensions;
19761973
sourceTree = "<group>";
@@ -3037,7 +3034,6 @@
30373034
35C77F621FE8219900338416 /* NavigationSettings.swift in Sources */,
30383035
41B901EB271048BD007F9F78 /* HistoryRecording.swift in Sources */,
30393036
DA5F44C825F07AB700F573EC /* MapboxStreetsRoadClass.swift in Sources */,
3040-
B44E1A802891DD350093743C /* CLLocationCoordinate2D.swift in Sources */,
30413037
2B5A4AC728099FA900170A2B /* AlternativeRoute.swift in Sources */,
30423038
2E50E0C0264E35CA009D3848 /* RoadObjectMatcher.swift in Sources */,
30433039
C51DF8661F38C31C006C6A15 /* Locale.swift in Sources */,

Sources/MapboxCoreNavigation/CLLocationCoordinate2D.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

Sources/MapboxNavigation/NavigationMapView+BuildingHighlighting.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ import Turf
44

55
extension NavigationMapView {
66

7+
struct CLLocationCoordinate2DHashable: Hashable {
8+
var coordinate: CLLocationCoordinate2D
9+
10+
init(_ coordinate: CLLocationCoordinate2D) {
11+
self.coordinate = coordinate
12+
}
13+
14+
func hash(into hasher: inout Hasher) {
15+
hasher.combine(coordinate.latitude)
16+
hasher.combine(coordinate.longitude)
17+
}
18+
19+
static func == (lhs: CLLocationCoordinate2DHashable,
20+
rhs: CLLocationCoordinate2DHashable) -> Bool {
21+
return lhs.coordinate.latitude == rhs.coordinate.latitude &&
22+
lhs.coordinate.longitude == rhs.coordinate.longitude
23+
}
24+
}
25+
726
// MARK: Building Extrusion Highlighting
827

928
/**
@@ -23,7 +42,9 @@ extension NavigationMapView {
2342
in3D extrudesBuildings: Bool = true,
2443
extrudeAll: Bool = false,
2544
completion: ((_ foundAllBuildings: Bool) -> Void)? = nil) {
26-
highlightedBuildingIdentifiersByCoordinate = highlightedBuildingIdentifiersByCoordinate.filter{ coordinates.contains($0.key) }
45+
highlightedBuildingIdentifiersByCoordinate = highlightedBuildingIdentifiersByCoordinate.filter {
46+
coordinates.contains($0.key.coordinate)
47+
}
2748
let group = DispatchGroup()
2849
let identifiers = mapView.mapboxMap.style.allLayerIdentifiers
2950
.compactMap({ $0.id })
@@ -51,7 +72,8 @@ extension NavigationMapView {
5172

5273
if case .success(let queriedFeatures) = result {
5374
if let identifier = queriedFeatures.first?.feature.featureIdentifier {
54-
self.highlightedBuildingIdentifiersByCoordinate[coordinate] = identifier
75+
let coordinate2DHashable = CLLocationCoordinate2DHashable.init(coordinate)
76+
self.highlightedBuildingIdentifiersByCoordinate[coordinate2DHashable] = identifier
5577
}
5678
}
5779
})

Sources/MapboxNavigation/NavigationMapView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ open class NavigationMapView: UIView {
920920
/**
921921
The coordinates and corresponding identifiers for highlight buildings.
922922
*/
923-
var highlightedBuildingIdentifiersByCoordinate = [CLLocationCoordinate2D: Int64]()
923+
var highlightedBuildingIdentifiersByCoordinate = [CLLocationCoordinate2DHashable: Int64]()
924924

925925
func setupUserLocation() {
926926
if !isAuthorized() { return }

Tests/MapboxNavigationTests/NavigationViewControllerTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,17 @@ extension NavigationViewControllerTests: NavigationViewControllerDelegate, Style
529529
}
530530
}
531531

532+
extension CLLocationCoordinate2D: Hashable {
533+
public func hash(into hasher: inout Hasher) {
534+
hasher.combine(latitude)
535+
hasher.combine(longitude)
536+
}
537+
538+
static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
539+
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
540+
}
541+
}
542+
532543
extension NavigationViewControllerTests {
533544
fileprivate func location(at coordinate: CLLocationCoordinate2D) -> CLLocation {
534545
return CLLocation(coordinate: coordinate,

0 commit comments

Comments
 (0)