Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Swift 5 #2232

Merged
merged 9 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Example/CustomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion Example/SettingsItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Example/ViewController+GuidanceCards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions MapboxCoreNavigation/EventDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/LegacyRouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions MapboxCoreNavigation/MBNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extension MBRouteState: CustomStringConvertible {
return "offRoute"
case .stale:
return "stale"
@unknown default:
fatalError("Indescribable route state \(rawValue)")
}
}
}
18 changes: 9 additions & 9 deletions MapboxCoreNavigation/NavigationEventsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,33 +208,33 @@ 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()
}

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)
}

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions MapboxCoreNavigation/RouteProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/SimulatedLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions MapboxCoreNavigationTests/DistanceFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigationTests/RouteProgressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation-Documentation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion MapboxNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 8 additions & 10 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/InstructionPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/RatingControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading