-
Notifications
You must be signed in to change notification settings - Fork 322
Upgrade to swift 4 #663
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
Upgrade to swift 4 #663
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to maintain Swift 3 support by changing SWIFT_VERSION
back to 3.1 and enclosing any incompatible code in #if swift
checks?
Let's see how many there are. This could become very tiresome if it's a lot of code. The other option is to maintain a branch for x more months... and with a set EOL. |
@@ -190,7 +190,7 @@ class GeometryTests: XCTestCase { | |||
|
|||
// https://github.com/Turfjs/turf/blob/142e137ce0c758e2825a260ab32b24db0aa19439/packages/turf-distance/test.js | |||
let a = distance(along: line) | |||
XCTAssertEqualWithAccuracy(a, 97_159.57803131901, accuracy: 1) | |||
XCTAssertEqual(a, 97_159.57803131901, accuracy: 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't build using an earlier version.
Try adding: https://github.com/mapbox/turf-swift/blob/e17d1d05c08796536dea0b36a38b9c2bbde0fb06/TurfTests/TurfTests.swift#L7-L12
Should we add an additional Bitrise app with the new Xcode 9 stack? |
Yes, we should test both. |
b4f150f
to
e35203a
Compare
Added bitrise test for xcode 9. It will only run on this branch. |
So I added quite a few |
A line line https://github.com/mapbox/mapbox-navigation-ios/pull/663/files#diff-851f438872328e98cbe395ac0733c16bR130 will not accept the prefix |
Not sure which line you’re referring to, but there are probably a number of methods that never bridged to Objective-C. Let’s track those issues separately. Making these situations explicit is one of the benefits of Swift 4’s |
1e22f1a
to
7d7ba69
Compare
@@ -17,13 +17,13 @@ open class NavigationLocationManager: CLLocationManager { | |||
/** | |||
Indicates whether the device is plugged in or not. | |||
*/ | |||
public private(set) var isPluggedIn: Bool = false | |||
@objc public private(set) var isPluggedIn: Bool = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private(set)
I did not know you could do that.
We'll need to update MapboxDirections.swift to swift 4 before merging this. |
This is blocked by CocoaPods/CocoaPods#7134 |
Is it really blocked? This PR was designed to work when compiled as Swift 3, so we could have Carthage compiling it as Swift 4 and CocoaPods compiling it as Swift 3 for the time being. |
@1ec5 I guess that would work. |
Cartfile
Outdated
@@ -2,7 +2,7 @@ binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 3.6 | |||
github "mapbox/MapboxDirections.swift" ~> 0.12 | |||
github "mapbox/turf-swift" ~> 0.0.3 | |||
github "rs/SDWebImage" ~> 4.1 | |||
github "Project-OSRM/osrm-text-instructions.swift" ~> 0.5 | |||
github "Project-OSRM/osrm-text-instructions.swift" "f60d5bc175794aee6c7199d60548820e0fb23097" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change when Project-OSRM/osrm-text-instructions.swift#50 is released.
@mapbox/navigation-ios this is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is functionally sound, but there are a number of places where running the migrator resulted in unnecessarily verbose code.
@@ -126,7 +126,6 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |||
|
|||
MGLPointAnnotation *destination = [[MGLPointAnnotation alloc] init]; | |||
destination.coordinate = self.destination; | |||
controller.destination = destination; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this line removed? Doesn’t this cause the preceding two lines to be useless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destination
was deprecated eons ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So shouldn’t the two lines above be removed too?
@@ -21,7 +21,7 @@ class MapboxCoreNavigationTests: XCTestCase { | |||
navigation.resume() | |||
let depart = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 37.795042, longitude: -122.413165), altitude: 1, horizontalAccuracy: 1, verticalAccuracy: 1, course: 0, speed: 10, timestamp: Date()) | |||
|
|||
self.expectation(forNotification: RouteControllerDidPassSpokenInstructionPoint.rawValue, object: navigation) { (notification) -> Bool in | |||
self.expectation(forNotification: NSNotification.Name(rawValue: RouteControllerDidPassSpokenInstructionPoint.rawValue), object: navigation) { (notification) -> Bool in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RouteControllerDidPassSpokenInstructionPoint
directly instead of converting to a raw value and back to an NSNotification.Name
(×4).
@@ -6,13 +6,13 @@ extension BottomBannerView { | |||
|
|||
let timeRemainingLabel = TimeRemainingLabel() | |||
timeRemainingLabel.translatesAutoresizingMaskIntoConstraints = false | |||
timeRemainingLabel.font = .systemFont(ofSize: 28, weight: UIFontWeightMedium) | |||
timeRemainingLabel.font = .systemFont(ofSize: 28, weight: UIFont.Weight.medium) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop UIFont.Weight
(×2).
MapboxNavigation/DayStyle.swift
Outdated
@@ -58,22 +58,22 @@ open class DayStyle: Style { | |||
tintColor = .defaultTint | |||
} | |||
|
|||
ArrivalTimeLabel.appearance().font = UIFont.systemFont(ofSize: 18, weight: UIFontWeightMedium).adjustedFont | |||
ArrivalTimeLabel.appearance().font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium).adjustedFont |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop UIFont.Weight
(×10).
var attributes: [String: Any] { | ||
return [NSFontAttributeName: font, NSForegroundColorAttributeName: textColor] | ||
var attributes: [NSAttributedStringKey: Any] { | ||
return [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: textColor] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop NSAttributedStringKey
.
MapboxNavigation/Style.swift
Outdated
let valueAttributes: [String: Any] = [NSForegroundColorAttributeName: valueTextColor, NSFontAttributeName: valueFont] | ||
let unitAttributes: [String: Any] = [NSForegroundColorAttributeName: unitTextColor, NSFontAttributeName: unitFont] | ||
let valueAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.foregroundColor: valueTextColor, NSAttributedStringKey.font: valueFont] | ||
let unitAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.foregroundColor: unitTextColor, NSAttributedStringKey.font: unitFont] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop NSAttributedStringKey
from both these lines.
MapboxNavigation/UIFont.swift
Outdated
@@ -37,14 +37,14 @@ extension UIFont { | |||
|
|||
func with(fontFamily: String?) -> UIFont { | |||
guard let fontFamily = fontFamily else { return self } | |||
let weight = (fontDescriptor.object(forKey: UIFontDescriptorTraitsAttribute) as! [String:Any])[UIFontWeightTrait] | |||
let attributes = [UIFontDescriptorTraitsAttribute: [UIFontWeightTrait: weight]] | |||
let weight = (fontDescriptor.object(forKey: UIFontDescriptor.AttributeName.traits) as! [String:Any])[UIFontDescriptor.TraitKey.weight.rawValue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop UIFontDescriptor.AttributeName
.
MapboxNavigation/UIFont.swift
Outdated
let weight = (fontDescriptor.object(forKey: UIFontDescriptorTraitsAttribute) as! [String:Any])[UIFontWeightTrait] | ||
let attributes = [UIFontDescriptorTraitsAttribute: [UIFontWeightTrait: weight]] | ||
let weight = (fontDescriptor.object(forKey: UIFontDescriptor.AttributeName.traits) as! [String:Any])[UIFontDescriptor.TraitKey.weight.rawValue] | ||
let attributes = [UIFontDescriptor.AttributeName.traits: [UIFontDescriptor.TraitKey.weight: weight]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline this variable so that you can drop UIFontDescriptor.AttributeName
and possibly UIFontDescriptor.TraitKey
.
MapboxNavigation/UIFont.swift
Outdated
let descriptor = UIFontDescriptor(name: fontName, size: pointSize).withFamily(fontFamily).addingAttributes(attributes) | ||
return UIFont(descriptor: descriptor, size: pointSize) | ||
} | ||
|
||
func with(weight: CGFloat) -> UIFont { | ||
let font = UIFont(descriptor: fontDescriptor.addingAttributes([UIFontWeightTrait: weight]), size: pointSize) | ||
let font = UIFont(descriptor: fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.traits: weight]), size: pointSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop UIFontDescriptor.AttributeName
.
view.primaryLabel.font = UIFont.systemFont(ofSize: 30, weight: UIFontWeightMedium) | ||
view.secondaryLabel.font = UIFont.systemFont(ofSize: 26, weight: UIFontWeightMedium) | ||
view.primaryLabel.font = UIFont.systemFont(ofSize: 30, weight: UIFont.Weight.medium) | ||
view.secondaryLabel.font = UIFont.systemFont(ofSize: 26, weight: UIFont.Weight.medium) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: drop UIFont.Weight
from both these lines.
@1ec5 fixed. |
@@ -43,7 +43,7 @@ class MapboxCoreNavigationTests: XCTestCase { | |||
let locationManager = ReplayLocationManager(locations: [location, location]) | |||
let navigation = RouteController(along: route, directions: directions, locationManager: locationManager) | |||
|
|||
self.expectation(forNotification: NSNotification.Name(rawValue: RouteControllerDidPassSpokenInstructionPoint.rawValue), object: navigation) { (notification) -> Bool in | |||
self.expectation(forNotification: RouteControllerDidPassSpokenInstructionPoint), object: navigation) { (notification) -> Bool in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unbalanced parentheses are causing a build failure (×3).
Fixed a serving or two of copypasta in fcb0e12c0434a574d77a655c25723004c7b3f27b and ac5f85e2e8da6c710a0f902cedecacd4f83a6eb6. |
b176bbf
to
e7e45da
Compare
This begins the process of upgrading to swift 4.
/cc @1ec5 @ericrwolfe @frederoni