diff --git a/.circleci/config.yml b/.circleci/config.yml index ddfe1de73cf..7dc022a7701 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -184,8 +184,8 @@ workflows: iOS: "12.1" codecoverage: true - build-job: - name: "Xcode_10.1_iOS_10.3.1" - xcode: "10.1.0" + name: "Xcode_10.2_iOS_10.3.1" + xcode: "10.2.0" iOS: "10.3.1" test: false - pod-job: diff --git a/Example/CustomViewController.swift b/Example/CustomViewController.swift index b45faca65d6..3d9cdec4e7a 100644 --- a/Example/CustomViewController.swift +++ b/Example/CustomViewController.swift @@ -162,8 +162,8 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { // find the leg that contains the step, legIndex, and stepIndex guard let leg = route.legs.first(where: { $0.steps.contains(step) }), - let legIndex = route.legs.index(of: leg), - let stepIndex = leg.steps.index(of: step) else { + let legIndex = route.legs.firstIndex(of: leg), + let stepIndex = leg.steps.firstIndex(of: step) else { return } diff --git a/Example/SettingsItems.swift b/Example/SettingsItems.swift index 8af8f5d8b3d..779070f4a89 100644 --- a/Example/SettingsItems.swift +++ b/Example/SettingsItems.swift @@ -105,7 +105,7 @@ extension SettingsViewController { extension URL { var directorySize: Int? { - guard ((try? resourceValues(forKeys: [.isDirectoryKey]).isDirectory) != nil) else { return nil } + guard (try? resourceValues(forKeys: [.isDirectoryKey]).isDirectory) as Bool?? != nil else { return nil } var directorySize = 0 (FileManager.default.enumerator(at: self, includingPropertiesForKeys: nil)?.allObjects as? [URL])?.lazy.forEach { diff --git a/Example/ViewController+GuidanceCards.swift b/Example/ViewController+GuidanceCards.swift index 1d837410eba..6a9b57e32c6 100644 --- a/Example/ViewController+GuidanceCards.swift +++ b/Example/ViewController+GuidanceCards.swift @@ -11,8 +11,8 @@ extension ViewController: InstructionsCardCollectionDelegate { // find the leg that contains the step, legIndex, and stepIndex guard let leg = route.legs.first(where: { $0.steps.contains(step) }), - let legIndex = route.legs.index(of: leg), - let stepIndex = leg.steps.index(of: step) else { + let legIndex = route.legs.firstIndex(of: leg), + let stepIndex = leg.steps.firstIndex(of: step) else { return } diff --git a/Example/ViewController.swift b/Example/ViewController.swift index ed552e42054..5d9952ebb21 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -387,7 +387,7 @@ extension ViewController: NavigationMapViewDelegate { func navigationMapView(_ mapView: NavigationMapView, didSelect route: Route) { guard let routes = routes else { return } - guard let index = routes.index(where: { $0 == route }) else { return } + guard let index = routes.firstIndex(where: { $0 == route }) else { return } self.routes!.remove(at: index) self.routes!.insert(route, at: 0) } diff --git a/MapboxCoreNavigation.podspec b/MapboxCoreNavigation.podspec index d2d1757dc87..d1fc12e53f0 100644 --- a/MapboxCoreNavigation.podspec +++ b/MapboxCoreNavigation.podspec @@ -45,6 +45,6 @@ Pod::Spec.new do |s| s.dependency "MapboxMobileEvents", "~> 0.9.5" # Always pin to a patch release if pre-1.0 s.dependency "Turf", "~> 0.3.0" # Always pin to a patch release if pre-1.0 - s.swift_version = "4.2" + s.swift_version = "5.0" end diff --git a/MapboxCoreNavigation/EventDetails.swift b/MapboxCoreNavigation/EventDetails.swift index ff68dd37945..8c6191c8e13 100644 --- a/MapboxCoreNavigation/EventDetails.swift +++ b/MapboxCoreNavigation/EventDetails.swift @@ -358,6 +358,8 @@ extension UIApplication.State: Encodable { stringRepresentation = "Inactive" case .background: stringRepresentation = "Background" + @unknown default: + fatalError("Indescribable application state \(rawValue)") } try container.encode(stringRepresentation) } diff --git a/MapboxCoreNavigation/LegacyRouteController.swift b/MapboxCoreNavigation/LegacyRouteController.swift index 089c5d6181d..1bf070b8ab6 100644 --- a/MapboxCoreNavigation/LegacyRouteController.swift +++ b/MapboxCoreNavigation/LegacyRouteController.swift @@ -310,7 +310,7 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa func updateIntersectionIndex(for currentStepProgress: RouteStepProgress) { guard let intersectionDistances = currentStepProgress.intersectionDistances else { return } - let upcomingIntersectionIndex = intersectionDistances.index { $0 > currentStepProgress.distanceTraveled } ?? intersectionDistances.endIndex + let upcomingIntersectionIndex = intersectionDistances.firstIndex { $0 > currentStepProgress.distanceTraveled } ?? intersectionDistances.endIndex currentStepProgress.intersectionIndex = upcomingIntersectionIndex > 0 ? intersectionDistances.index(before: upcomingIntersectionIndex) : 0 } diff --git a/MapboxCoreNavigation/MBNavigator.swift b/MapboxCoreNavigation/MBNavigator.swift index f6dec3cdf6a..f02ff435cc2 100644 --- a/MapboxCoreNavigation/MBNavigator.swift +++ b/MapboxCoreNavigation/MBNavigator.swift @@ -31,6 +31,8 @@ extension MBRouteState: CustomStringConvertible { return "offRoute" case .stale: return "stale" + @unknown default: + fatalError("Indescribable route state \(rawValue)") } } } diff --git a/MapboxCoreNavigation/NavigationEventsManager.swift b/MapboxCoreNavigation/NavigationEventsManager.swift index 26cece4fc53..2411d590c90 100644 --- a/MapboxCoreNavigation/NavigationEventsManager.swift +++ b/MapboxCoreNavigation/NavigationEventsManager.swift @@ -208,25 +208,25 @@ open class NavigationEventsManager: NSObject { } func sendRouteRetrievalEvent() { - guard let attributes = try? navigationRouteRetrievalEvent()?.asDictionary() else { return } + guard let attributes = (try? navigationRouteRetrievalEvent()?.asDictionary()) as [String: Any]?? else { return } mobileEventsManager.enqueueEvent(withName: NavigationEventTypeRouteRetrieval, attributes: attributes ?? [:]) mobileEventsManager.flush() } func sendDepartEvent() { - guard let attributes = try? navigationDepartEvent()?.asDictionary() else { return } + guard let attributes = (try? navigationDepartEvent()?.asDictionary()) as [String: Any]?? else { return } mobileEventsManager.enqueueEvent(withName: MMEEventTypeNavigationDepart, attributes: attributes ?? [:]) mobileEventsManager.flush() } func sendArriveEvent() { - guard let attributes = try? navigationArriveEvent()?.asDictionary() else { return } + guard let attributes = (try? navigationArriveEvent()?.asDictionary()) as [String: Any]?? else { return } mobileEventsManager.enqueueEvent(withName: MMEEventTypeNavigationArrive, attributes: attributes ?? [:]) mobileEventsManager.flush() } func sendCancelEvent(rating: Int? = nil, comment: String? = nil) { - guard let attributes = try? navigationCancelEvent(rating: rating, comment: comment)?.asDictionary() else { return } + guard let attributes = (try? navigationCancelEvent(rating: rating, comment: comment)?.asDictionary()) as [String: Any]?? else { return } mobileEventsManager.enqueueEvent(withName: MMEEventTypeNavigationCancel, attributes: attributes ?? [:]) mobileEventsManager.flush() } @@ -234,7 +234,7 @@ open class NavigationEventsManager: NSObject { func sendFeedbackEvents(_ events: [CoreFeedbackEvent]) { events.forEach { event in // remove from outstanding event queue - if let index = outstandingFeedbackEvents.index(of: event) { + if let index = outstandingFeedbackEvents.firstIndex(of: event) { outstandingFeedbackEvents.remove(at: index) } @@ -247,14 +247,14 @@ open class NavigationEventsManager: NSObject { } func enqueueFeedbackEvent(type: FeedbackType, description: String?) -> UUID? { - guard let eventDictionary = try? navigationFeedbackEvent(type: type, description: description)?.asDictionary() else { return nil } + guard let eventDictionary = (try? navigationFeedbackEvent(type: type, description: description)?.asDictionary()) as [String: Any]?? else { return nil } let event = FeedbackEvent(timestamp: Date(), eventDictionary: eventDictionary ?? [:]) outstandingFeedbackEvents.append(event) return event.id } func enqueueRerouteEvent() { - guard let eventDictionary = try? navigationRerouteEvent()?.asDictionary() else { return } + guard let eventDictionary = (try? navigationRerouteEvent()?.asDictionary()) as [String: Any]?? else { return } let timestamp = dataSource?.router.location?.timestamp ?? Date() sessionState?.lastRerouteDate = timestamp @@ -273,7 +273,7 @@ open class NavigationEventsManager: NSObject { } func enqueueFoundFasterRouteEvent() { - guard let eventDictionary = try? navigationRerouteEvent(eventType: FasterRouteFoundEvent)?.asDictionary() else { return } + guard let eventDictionary = (try? navigationRerouteEvent(eventType: FasterRouteFoundEvent)?.asDictionary()) as [String: Any]?? else { return } let timestamp = Date() sessionState?.lastRerouteDate = timestamp @@ -334,7 +334,7 @@ open class NavigationEventsManager: NSObject { Discard a recorded feedback event, for example if you have a custom feedback UI and the user canceled feedback. */ @objc public func cancelFeedback(uuid: UUID) { - if let index = outstandingFeedbackEvents.index(where: {$0.id == uuid}) { + if let index = outstandingFeedbackEvents.firstIndex(where: {$0.id == uuid}) { outstandingFeedbackEvents.remove(at: index) } } diff --git a/MapboxCoreNavigation/RouteProgress.swift b/MapboxCoreNavigation/RouteProgress.swift index d4645ab5a04..1da2d600581 100644 --- a/MapboxCoreNavigation/RouteProgress.swift +++ b/MapboxCoreNavigation/RouteProgress.swift @@ -330,7 +330,7 @@ open class RouteLegProgress: NSObject { Returns the `RouteStep` before a given step. Returns `nil` if there is no step prior. */ @objc public func stepBefore(_ step: RouteStep) -> RouteStep? { - guard let index = leg.steps.index(of: step) else { + guard let index = leg.steps.firstIndex(of: step) else { return nil } if index > 0 { @@ -343,7 +343,7 @@ open class RouteLegProgress: NSObject { Returns the `RouteStep` after a given step. Returns `nil` if there is not a step after. */ @objc public func stepAfter(_ step: RouteStep) -> RouteStep? { - guard let index = leg.steps.index(of: step) else { + guard let index = leg.steps.firstIndex(of: step) else { return nil } if index+1 < leg.steps.endIndex { diff --git a/MapboxCoreNavigation/SimulatedLocationManager.swift b/MapboxCoreNavigation/SimulatedLocationManager.swift index 1849ff2a24c..b8d81f34409 100644 --- a/MapboxCoreNavigation/SimulatedLocationManager.swift +++ b/MapboxCoreNavigation/SimulatedLocationManager.swift @@ -235,7 +235,7 @@ extension Array where Element : Hashable { extension Array where Element : Equatable { fileprivate func after(element: Element) -> Element? { - if let index = self.index(of: element), index + 1 <= self.count { + if let index = self.firstIndex(of: element), index + 1 <= self.count { return index + 1 == self.count ? self[0] : self[index + 1] } return nil diff --git a/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/PodInstall.xcodeproj/project.pbxproj b/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/PodInstall.xcodeproj/project.pbxproj index e21a8628e1d..863f97fb7ff 100644 --- a/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/PodInstall.xcodeproj/project.pbxproj +++ b/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/PodInstall.xcodeproj/project.pbxproj @@ -231,8 +231,8 @@ "${PODS_ROOT}/Target Support Files/Pods-PodInstall/Pods-PodInstall-frameworks.sh", "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework", "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM", - "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/F1CD9014-347B-3A12-985D-D2CF4457B073.bcsymbolmap", - "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/C3BF5D38-E18B-392C-BFDF-5551F3CC528B.bcsymbolmap", + "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/F6FDF133-0198-394E-9C8F-5043F94B4790.bcsymbolmap", + "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/B4615DAE-86F8-35AB-B4D1-B1F1420E374A.bcsymbolmap", "${BUILT_PRODUCTS_DIR}/MapboxCoreNavigation/MapboxCoreNavigation.framework", "${BUILT_PRODUCTS_DIR}/MapboxDirections.swift/MapboxDirections.framework", "${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework", @@ -248,8 +248,8 @@ outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework", "${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM", - "${BUILT_PRODUCTS_DIR}/F1CD9014-347B-3A12-985D-D2CF4457B073.bcsymbolmap", - "${BUILT_PRODUCTS_DIR}/C3BF5D38-E18B-392C-BFDF-5551F3CC528B.bcsymbolmap", + "${BUILT_PRODUCTS_DIR}/F6FDF133-0198-394E-9C8F-5043F94B4790.bcsymbolmap", + "${BUILT_PRODUCTS_DIR}/B4615DAE-86F8-35AB-B4D1-B1F1420E374A.bcsymbolmap", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCoreNavigation.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxDirections.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", diff --git a/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/Podfile.lock b/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/Podfile.lock index 05f6f34b414..4c1ec29cc3f 100644 --- a/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/Podfile.lock +++ b/MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - Mapbox-iOS-SDK (5.3.2) + - Mapbox-iOS-SDK (5.4.0) - MapboxCoreNavigation (0.37.0): - MapboxDirections.swift (~> 0.30.0) - MapboxMobileEvents (~> 0.9.5) @@ -41,11 +41,11 @@ EXTERNAL SOURCES: :path: "../../../" SPEC CHECKSUMS: - Mapbox-iOS-SDK: 23c20a5da344234cafba5d13669af3f8bde8beaa - MapboxCoreNavigation: 3fab73d620f8787d234fa268619457efe2e611ec + Mapbox-iOS-SDK: 2b58f752d94e57e95b8e54f3b52569199f6efdba + MapboxCoreNavigation: fd30e78f70471462682c0f05a7708861feae30ff MapboxDirections.swift: 1c6df988c24b753888ebd9976d7c98632501a413 MapboxMobileEvents: f6c21b2e59066c5c7093585de7c15adae3b63da0 - MapboxNavigation: 6b76631fc24d28380d187cba5d912f5167898a70 + MapboxNavigation: 5f3ccb117173abcac3c8218cbc0bd3b736c57857 MapboxNavigationNative: 11dc22140f4698d3f26989f2b6379dc81ef0d4c1 MapboxSpeech: 59b3984d3f433a443d24acf53097f918c5cc70f9 Polyline: 0e9890790292741c8186201a536b6bb6a78d02dd diff --git a/MapboxCoreNavigationTests/DistanceFormatterTests.swift b/MapboxCoreNavigationTests/DistanceFormatterTests.swift index eeb7fd1e97c..34de68f8b7b 100644 --- a/MapboxCoreNavigationTests/DistanceFormatterTests.swift +++ b/MapboxCoreNavigationTests/DistanceFormatterTests.swift @@ -30,14 +30,14 @@ class DistanceFormatterTests: XCTestCase { } var effectiveQuantityRange = NSRange(location: NSNotFound, length: 0) - let quantityAttrs = checkedAttributedString.attributes(at: checkedQuantityRange.lowerBound.encodedOffset, effectiveRange: &effectiveQuantityRange) + let quantityAttrs = checkedAttributedString.attributes(at: checkedQuantityRange.lowerBound.utf16Offset(in: checkedAttributedString.string), effectiveRange: &effectiveQuantityRange) XCTAssertEqual(quantityAttrs[.quantity] as? NSNumber, value as NSNumber, "'\(quantity)' should have quantity \(measurement.distance)") XCTAssertEqual(effectiveQuantityRange.length, quantity.count) - guard checkedQuantityRange.upperBound.encodedOffset < checkedAttributedString.length else { + guard checkedQuantityRange.upperBound.utf16Offset(in: checkedAttributedString.string) < checkedAttributedString.length else { return } - let unitAttrs = checkedAttributedString.attributes(at: checkedQuantityRange.upperBound.encodedOffset, effectiveRange: nil) + let unitAttrs = checkedAttributedString.attributes(at: checkedQuantityRange.upperBound.utf16Offset(in: checkedAttributedString.string), effectiveRange: nil) XCTAssertNil(unitAttrs[.quantity], "Unit should not be emphasized like a quantity") } diff --git a/MapboxCoreNavigationTests/RouteProgressTests.swift b/MapboxCoreNavigationTests/RouteProgressTests.swift index 697fffa2212..c3155bc6db1 100644 --- a/MapboxCoreNavigationTests/RouteProgressTests.swift +++ b/MapboxCoreNavigationTests/RouteProgressTests.swift @@ -48,7 +48,7 @@ class RouteProgressTests: XCTestCase { } func testRemainingWaypointsAlongRoute() { - var coordinates = [ + let coordinates = [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 2, longitude: 3), CLLocationCoordinate2D(latitude: 4, longitude: 6), diff --git a/MapboxNavigation-Documentation.podspec b/MapboxNavigation-Documentation.podspec index cbed0d24fb1..cb49d0299ca 100644 --- a/MapboxNavigation-Documentation.podspec +++ b/MapboxNavigation-Documentation.podspec @@ -53,6 +53,6 @@ Pod::Spec.new do |s| s.dependency "Turf", "~> 0.3.0" s.dependency "MapboxSpeech", "~> 0.1" - s.swift_version = "4.2" + s.swift_version = "5.0" end diff --git a/MapboxNavigation.podspec b/MapboxNavigation.podspec index 40ab3ef1980..c3bc1735dff 100644 --- a/MapboxNavigation.podspec +++ b/MapboxNavigation.podspec @@ -48,6 +48,6 @@ Pod::Spec.new do |s| s.dependency "Solar", "~> 2.1" s.dependency "MapboxSpeech", "~> 0.1.0" - s.swift_version = "4.2" + s.swift_version = "5.0" end diff --git a/MapboxNavigation.xcodeproj/project.pbxproj b/MapboxNavigation.xcodeproj/project.pbxproj index 5b620c4e3cf..942ac12e6a4 100644 --- a/MapboxNavigation.xcodeproj/project.pbxproj +++ b/MapboxNavigation.xcodeproj/project.pbxproj @@ -2003,19 +2003,19 @@ 351BEBD61E5BCC28006FE110 = { CreatedOnToolsVersion = 8.2.1; DevelopmentTeam = GJZR2MEM28; - LastSwiftMigration = 1010; + LastSwiftMigration = 1030; ProvisioningStyle = Automatic; }; 358D14621E5E3B7700ADE590 = { CreatedOnToolsVersion = 8.2.1; DevelopmentTeam = GJZR2MEM28; - LastSwiftMigration = 1010; + LastSwiftMigration = 1030; ProvisioningStyle = Automatic; }; 35B711CE1E5E7AD2001EDA8D = { CreatedOnToolsVersion = 8.2.1; DevelopmentTeam = GJZR2MEM28; - LastSwiftMigration = 0910; + LastSwiftMigration = 1030; ProvisioningStyle = Automatic; TestTargetID = 358D14621E5E3B7700ADE590; }; @@ -2044,18 +2044,18 @@ 35CDA85D2190F2A30072B675 = { CreatedOnToolsVersion = 10.1; DevelopmentTeam = GJZR2MEM28; - LastSwiftMigration = 1020; + LastSwiftMigration = 1030; ProvisioningStyle = Automatic; }; C53F2EDE20EBC95600D9798F = { DevelopmentTeam = GJZR2MEM28; - LastSwiftMigration = 1010; + LastSwiftMigration = 1030; ProvisioningStyle = Manual; }; C5ADFBC81DDCC7840011824B = { CreatedOnToolsVersion = 8.1; DevelopmentTeam = GJZR2MEM28; - LastSwiftMigration = 1010; + LastSwiftMigration = 1030; ProvisioningStyle = Automatic; }; C5ADFBD11DDCC7840011824B = { @@ -3078,7 +3078,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxNavigationTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "MapboxNavigationTests/MapboxNavigationTests-Bridging.h"; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; }; name = Debug; @@ -3097,7 +3096,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxNavigationTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "MapboxNavigationTests/MapboxNavigationTests-Bridging.h"; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; }; name = Release; @@ -3445,7 +3443,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -3501,7 +3499,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; diff --git a/MapboxNavigation/InstructionPresenter.swift b/MapboxNavigation/InstructionPresenter.swift index 1248fe2829c..20a4f4474db 100644 --- a/MapboxNavigation/InstructionPresenter.swift +++ b/MapboxNavigation/InstructionPresenter.swift @@ -313,7 +313,7 @@ fileprivate struct IndexedVisualInstructionComponent { extension Array where Element == VisualInstructionComponent { fileprivate func component(before component: VisualInstructionComponent) -> VisualInstructionComponent? { - guard let index = self.index(of: component) else { + guard let index = self.firstIndex(of: component) else { return nil } if index > 0 { @@ -323,7 +323,7 @@ extension Array where Element == VisualInstructionComponent { } fileprivate func component(after component: VisualInstructionComponent) -> VisualInstructionComponent? { - guard let index = self.index(of: component) else { + guard let index = self.firstIndex(of: component) else { return nil } if index+1 < self.endIndex { diff --git a/MapboxNavigation/NavigationViewController.swift b/MapboxNavigation/NavigationViewController.swift index 0247b1a9ef1..eb5df6c3363 100644 --- a/MapboxNavigation/NavigationViewController.swift +++ b/MapboxNavigation/NavigationViewController.swift @@ -687,8 +687,8 @@ extension NavigationViewController: TopBannerViewControllerDelegate { public func preview(step: RouteStep, in banner: TopBannerViewController, remaining: [RouteStep], route: Route, animated: Bool = true) { guard let leg = route.leg(containing: step) else { return } - guard let legIndex = route.legs.index(of: leg) else { return } - guard let stepIndex = leg.steps.index(of: step) else { return } + guard let legIndex = route.legs.firstIndex(of: leg) else { return } + guard let stepIndex = leg.steps.firstIndex(of: step) else { return } let nextStepIndex = stepIndex + 1 let legProgress = RouteLegProgress(leg: leg, stepIndex: stepIndex) diff --git a/MapboxNavigation/RatingControl.swift b/MapboxNavigation/RatingControl.swift index edd2d745f23..fd9f2c127f5 100644 --- a/MapboxNavigation/RatingControl.swift +++ b/MapboxNavigation/RatingControl.swift @@ -126,7 +126,7 @@ class RatingControl: UIStackView { } @objc private func ratingButtonTapped(button sender: UIButton) { - guard let index = stars.index(of: sender) else { return assertionFailure("RatingControl.swift: The Star button that was tapped was not found in the RatingControl.stars array. This should never happen.") } + guard let index = stars.firstIndex(of: sender) else { return assertionFailure("RatingControl.swift: The Star button that was tapped was not found in the RatingControl.stars array. This should never happen.") } let selectedRating = index + 1 rating = (selectedRating == rating) ? 0 : selectedRating diff --git a/MapboxNavigation/RecentItem.swift b/MapboxNavigation/RecentItem.swift index b972ccf354a..a4486a14695 100644 --- a/MapboxNavigation/RecentItem.swift +++ b/MapboxNavigation/RecentItem.swift @@ -48,7 +48,7 @@ extension Array where Element == RecentItem { func save() { let encoder = JSONEncoder() let data = try? encoder.encode(self) - try? data?.write(to: RecentItem.filePathUrl) + (try? data?.write(to: RecentItem.filePathUrl)) as ()?? } mutating func add(_ recentItem: RecentItem) { @@ -66,7 +66,7 @@ extension Array where Element == RecentItem { } mutating func remove(_ recentItem: RecentItem) { - if let index = index(of: recentItem) { + if let index = firstIndex(of: recentItem) { remove(at: index) } } diff --git a/MapboxNavigation/StatusView.swift b/MapboxNavigation/StatusView.swift index a35f2f70a32..82c96c05c18 100644 --- a/MapboxNavigation/StatusView.swift +++ b/MapboxNavigation/StatusView.swift @@ -115,11 +115,10 @@ public class StatusView: UIControl { if sender.state == .ended { let incrementer: Double - switch UIApplication.shared.userInterfaceLayoutDirection { - case .leftToRight: - incrementer = location.x > bounds.midX ? 0.1 : -0.1 - case .rightToLeft: + if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft { incrementer = location.x < bounds.midX ? 0.1 : -0.1 + } else { + incrementer = location.x > bounds.midX ? 0.1 : -0.1 } value = min(max(value + incrementer, 0), 1) } diff --git a/MapboxNavigation/Style.swift b/MapboxNavigation/Style.swift index 26283968dca..84b4765d0f3 100644 --- a/MapboxNavigation/Style.swift +++ b/MapboxNavigation/Style.swift @@ -481,11 +481,10 @@ public class ProgressBar: UIView { func updateProgressBar() { if let superview = superview { let origin: CGPoint - switch UIApplication.shared.userInterfaceLayoutDirection { - case .leftToRight: - origin = .zero - case .rightToLeft: + if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft { origin = CGPoint(x: superview.bounds.width * (1 - progress), y: 0) + } else { + origin = .zero } bar.frame = CGRect(origin: origin, size: CGSize(width: superview.bounds.width * progress, height: bounds.height)) } diff --git a/MapboxNavigation/TopBannerViewController.swift b/MapboxNavigation/TopBannerViewController.swift index b85b55f45c7..7e22474bf6a 100644 --- a/MapboxNavigation/TopBannerViewController.swift +++ b/MapboxNavigation/TopBannerViewController.swift @@ -287,7 +287,7 @@ import MapboxDirections } public func preview(step stepOverride: RouteStep? = nil, maneuverStep: RouteStep, distance: CLLocationDistance, steps: [RouteStep], completion: CompletionHandler? = nil) { - guard !steps.isEmpty, let step = stepOverride ?? steps.first, let index = steps.index(of: step) else { + guard !steps.isEmpty, let step = stepOverride ?? steps.first, let index = steps.firstIndex(of: step) else { return // do nothing if there are no steps provided to us. } //this must happen before the preview steps are set diff --git a/MapboxNavigationTests/InstructionsBannerViewIntegrationTests.swift b/MapboxNavigationTests/InstructionsBannerViewIntegrationTests.swift index 53f320540dc..001bbcfc8b0 100644 --- a/MapboxNavigationTests/InstructionsBannerViewIntegrationTests.swift +++ b/MapboxNavigationTests/InstructionsBannerViewIntegrationTests.swift @@ -102,7 +102,7 @@ class InstructionsBannerViewIntegrationTests: XCTestCase { view.update(for: makeVisualInstruction(primaryInstruction: instructions, secondaryInstruction: nil)) - XCTAssertNotNil(view.primaryLabel.text!.index(of: "/")) + XCTAssertNotNil(view.primaryLabel.text!.firstIndex(of: "/")) } func testDelimiterIsHiddenWhenAllShieldsAreAlreadyLoaded() { @@ -117,7 +117,7 @@ class InstructionsBannerViewIntegrationTests: XCTestCase { view.update(for: makeVisualInstruction(primaryInstruction: instructions, secondaryInstruction: nil)) //the delimiter should NOT be present since both shields are already in the cache - XCTAssertNil(view.primaryLabel.text!.index(of: "/")) + XCTAssertNil(view.primaryLabel.text!.firstIndex(of: "/")) //explicitly reset the cache resetImageCache() @@ -139,7 +139,7 @@ class InstructionsBannerViewIntegrationTests: XCTestCase { view.update(for: makeVisualInstruction(primaryInstruction: instructions, secondaryInstruction: nil)) //Slash should be present until an adjacent shield is downloaded - XCTAssertNotNil(view.primaryLabel.text!.index(of: "/")) + XCTAssertNotNil(view.primaryLabel.text!.firstIndex(of: "/")) //simulate the downloads let firstDestinationComponent: VisualInstructionComponent = instructions[0] @@ -158,7 +158,7 @@ class InstructionsBannerViewIntegrationTests: XCTestCase { wait(for: [secondExpectation], timeout: 1) //Slash should no longer be present - XCTAssertNil(view.primaryLabel.text!.index(of: "/"), "Expected instruction text not to contain a slash: \(view.primaryLabel.text!)") + XCTAssertNil(view.primaryLabel.text!.firstIndex(of: "/"), "Expected instruction text not to contain a slash: \(view.primaryLabel.text!)") } func testGenericRouteShieldInstructionsArePresentedProperly() { diff --git a/MapboxNavigationTests/LaneTests.swift b/MapboxNavigationTests/LaneTests.swift index 66a2c2c697d..1c18e83cdf8 100644 --- a/MapboxNavigationTests/LaneTests.swift +++ b/MapboxNavigationTests/LaneTests.swift @@ -40,14 +40,11 @@ class LaneTests: FBSnapshotTestCase { laneView.drivingSide = lane.drivingSide laneView.backgroundColor = .white - laneView.widthAnchor.constraint(equalToConstant: size.width) - laneView.heightAnchor.constraint(equalToConstant: size.height) laneView.bounds = CGRect(origin: .zero, size: size) let label = UILabel(frame: .zero) label.textColor = .white label.text = "\(lane.description) (\(lane.drivingSide == .left ? "L" : "R"))" - label.widthAnchor.constraint(equalTo: laneView.widthAnchor) groupView.addArrangedSubview(label) groupView.addArrangedSubview(laneView) diff --git a/MapboxNavigationTests/NavigationViewControllerTests.swift b/MapboxNavigationTests/NavigationViewControllerTests.swift index d16e87bcf21..a604b3260bb 100644 --- a/MapboxNavigationTests/NavigationViewControllerTests.swift +++ b/MapboxNavigationTests/NavigationViewControllerTests.swift @@ -282,9 +282,9 @@ extension NavigationViewControllerTests: NavigationViewControllerDelegate, Style } extension CLLocationCoordinate2D: Hashable { - // Hash value property multiplied by a prime constant. - public var hashValue: Int { - return latitude.hashValue ^ longitude.hashValue &* 16777619 + public func hash(into hasher: inout Hasher) { + hasher.combine(latitude) + hasher.combine(longitude) } static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool { diff --git a/README.md b/README.md index fc0f790775f..19593d86bf7 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,7 @@ Get up and running in a few minutes with our drop-in turn-by-turn navigation `Na ## Requirements -The Mapbox Navigation SDK and Core Navigation are compatible with applications written in Swift 4.2 or Objective-C in Xcode 10.0. The Mapbox Navigation and Mapbox Core Navigation frameworks run on iOS 10.0 and above. - -The last release compatible with Swift 3.2 was v0.10.1. The last release compatible with iOS 9._x_ was v0.36.0. +The Mapbox Navigation SDK and Core Navigation are compatible with applications written in Swift or Objective-C in Xcode 10.2 and above. The Mapbox Navigation and Mapbox Core Navigation frameworks run on iOS 10.0 and above. The Mapbox Navigation SDK is also available [for Android](https://github.com/mapbox/mapbox-navigation-android/). diff --git a/TestHelper/NavigationEventsManagerTestDoubles.swift b/TestHelper/NavigationEventsManagerTestDoubles.swift index 0a65680450e..c2367b644ef 100644 --- a/TestHelper/NavigationEventsManagerTestDoubles.swift +++ b/TestHelper/NavigationEventsManagerTestDoubles.swift @@ -2,7 +2,6 @@ import Foundation import MapboxMobileEvents @testable import MapboxCoreNavigation import MapboxDirections -import TestHelper public class NavigationEventsManagerSpy: NavigationEventsManager {