Skip to content

Commit

Permalink
Merge pull request #393 from mapbox/jerrad/delenda-duet-dependencies
Browse files Browse the repository at this point in the history
Objective-C removal followups for navigation SDK compatibility
  • Loading branch information
1ec5 authored Dec 25, 2019
2 parents ff9997d + 472cbce commit 4d91bb2
Show file tree
Hide file tree
Showing 27 changed files with 579 additions and 140 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* Removed `TransportType.none`, `ManeuverType.none`, and `ManeuverDirection.none`. Unrecognized `TransportType` and `ManeuverDirection` values now raise decoding errors. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* `RouteStep.maneuverType` is now optional. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Renamed the `Tracepoint.alternateCount` property to `Tracepoint.countOfAlternatives`. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* The `Intersection.approachIndex` and `Intersection.outletIndex` properties are now optional, not −1, in the case of a departure or arrival maneuver. ([#393](https://github.com/mapbox/MapboxDirections.swift/pull/393))
* Added initializers for `Route`, `Match`, `RouteLeg`, and `RouteStep`. ([#393](https://github.com/mapbox/MapboxDirections.swift/pull/393))
* Various properties of `Route`, `RouteLeg`, and `RouteStep` are now writable. ([#393](https://github.com/mapbox/MapboxDirections.swift/pull/393))

## v0.30.0

Expand Down
16 changes: 16 additions & 0 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@
DADD27C81E5AAE3100D31FAD /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DADD27C71E5AAE3100D31FAD /* Launch Screen.storyboard */; };
DADD27F31E5ABD4300D31FAD /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DADD27F21E5ABD4300D31FAD /* Mapbox.framework */; };
DADD27F71E5AC8E900D31FAD /* MapboxDirections.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA6C9D881CAE442B00094FBC /* MapboxDirections.framework */; };
DAE2DF6823AECB120065057A /* QuickLookTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2DF6723AECB120065057A /* QuickLookTests.swift */; };
DAE2DF6923AECB120065057A /* QuickLookTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2DF6723AECB120065057A /* QuickLookTests.swift */; };
DAE2DF6A23AECB120065057A /* QuickLookTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2DF6723AECB120065057A /* QuickLookTests.swift */; };
DAE2DF6C23AED2280065057A /* RouteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2DF6B23AED2280065057A /* RouteTests.swift */; };
DAE2DF6D23AED2280065057A /* RouteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2DF6B23AED2280065057A /* RouteTests.swift */; };
DAE2DF6E23AED2280065057A /* RouteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2DF6B23AED2280065057A /* RouteTests.swift */; };
DAE33A1B1F215DF600C06039 /* IntersectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE33A1A1F215DF600C06039 /* IntersectionTests.swift */; };
DAE33A1C1F215DF600C06039 /* IntersectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE33A1A1F215DF600C06039 /* IntersectionTests.swift */; };
DAE33A1D1F215DF600C06039 /* IntersectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE33A1A1F215DF600C06039 /* IntersectionTests.swift */; };
Expand Down Expand Up @@ -402,6 +408,8 @@
DADD27C31E5AAAD800D31FAD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DADD27C71E5AAE3100D31FAD /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
DADD27F21E5ABD4300D31FAD /* Mapbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Mapbox.framework; path = Carthage/Build/iOS/Mapbox.framework; sourceTree = "<group>"; };
DAE2DF6723AECB120065057A /* QuickLookTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickLookTests.swift; sourceTree = "<group>"; };
DAE2DF6B23AED2280065057A /* RouteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteTests.swift; sourceTree = "<group>"; };
DAE33A1A1F215DF600C06039 /* IntersectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntersectionTests.swift; sourceTree = "<group>"; };
DAE9E0F31EB7DE2E001E8E8B /* RouteOptionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RouteOptionsTests.swift; path = Tests/MapboxDirectionsTests/RouteOptionsTests.swift; sourceTree = SOURCE_ROOT; };
DD6254731AE70CB700017857 /* Directions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Directions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -635,7 +643,9 @@
3556CE9922649CF2009397B5 /* MapboxDirectionsTests-Bridging-Header.h */,
C5DAACAE201AA92B001F9261 /* MatchTests.swift */,
35DBF013217E199E0009D2AE /* OfflineDirectionsTests.swift */,
DAE2DF6723AECB120065057A /* QuickLookTests.swift */,
C59666382048A20E00C45CE5 /* RoutableMatchTests.swift */,
DAE2DF6B23AED2280065057A /* RouteTests.swift */,
DAE9E0F31EB7DE2E001E8E8B /* RouteOptionsTests.swift */,
F4D785EE1DDD82C100FF4665 /* RouteStepTests.swift */,
DAABF78D2395ABA900CEEB61 /* SpokenInstructionTests.swift */,
Expand Down Expand Up @@ -1196,6 +1206,7 @@
buildActionMask = 2147483647;
files = (
DAE9E0F51EB7DE2E001E8E8B /* RouteOptionsTests.swift in Sources */,
DAE2DF6D23AED2280065057A /* RouteTests.swift in Sources */,
35DBF015217E199E0009D2AE /* OfflineDirectionsTests.swift in Sources */,
C53A02291E92C27A009837BD /* AnnotationTests.swift in Sources */,
DA688B3F21B89ECD00C9BB25 /* VisualInstructionComponentTests.swift in Sources */,
Expand All @@ -1205,6 +1216,7 @@
DAE33A1C1F215DF600C06039 /* IntersectionTests.swift in Sources */,
C5DAACB0201AA92B001F9261 /* MatchTests.swift in Sources */,
DA1A10CE1D00F972009F82FA /* Fixture.swift in Sources */,
DAE2DF6923AECB120065057A /* QuickLookTests.swift in Sources */,
DA1A110C1D01045E009F82FA /* DirectionsTests.swift in Sources */,
C5D1D7F31F6AFBD600A1C4F1 /* VisualInstructionTests.swift in Sources */,
DA4F84EE21C08BFB008A0434 /* WaypointTests.swift in Sources */,
Expand Down Expand Up @@ -1265,6 +1277,7 @@
buildActionMask = 2147483647;
files = (
DAE9E0F61EB7DE2E001E8E8B /* RouteOptionsTests.swift in Sources */,
DAE2DF6E23AED2280065057A /* RouteTests.swift in Sources */,
35DBF016217E199E0009D2AE /* OfflineDirectionsTests.swift in Sources */,
C53A022A1E92C27B009837BD /* AnnotationTests.swift in Sources */,
DA688B4021B89ECD00C9BB25 /* VisualInstructionComponentTests.swift in Sources */,
Expand All @@ -1274,6 +1287,7 @@
DAE33A1D1F215DF600C06039 /* IntersectionTests.swift in Sources */,
C5DAACB1201AA92B001F9261 /* MatchTests.swift in Sources */,
DA1A10F51D010251009F82FA /* Fixture.swift in Sources */,
DAE2DF6A23AECB120065057A /* QuickLookTests.swift in Sources */,
DA1A110D1D01045E009F82FA /* DirectionsTests.swift in Sources */,
C5D1D7F41F6AFBD600A1C4F1 /* VisualInstructionTests.swift in Sources */,
DA4F84EF21C08BFB008A0434 /* WaypointTests.swift in Sources */,
Expand Down Expand Up @@ -1378,6 +1392,7 @@
buildActionMask = 2147483647;
files = (
DAE9E0F41EB7DE2E001E8E8B /* RouteOptionsTests.swift in Sources */,
DAE2DF6C23AED2280065057A /* RouteTests.swift in Sources */,
35DBF014217E199E0009D2AE /* OfflineDirectionsTests.swift in Sources */,
C5247D711E818A24004B6154 /* AnnotationTests.swift in Sources */,
DA688B3E21B89ECD00C9BB25 /* VisualInstructionComponentTests.swift in Sources */,
Expand All @@ -1387,6 +1402,7 @@
DAE33A1B1F215DF600C06039 /* IntersectionTests.swift in Sources */,
C5DAACAF201AA92B001F9261 /* MatchTests.swift in Sources */,
DA6C9DB21CAECA0E00094FBC /* Fixture.swift in Sources */,
DAE2DF6823AECB120065057A /* QuickLookTests.swift in Sources */,
DA1A110B1D01045E009F82FA /* DirectionsTests.swift in Sources */,
C52CE3931F6AF6E70069963D /* VisualInstructionTests.swift in Sources */,
DA4F84ED21C08BFB008A0434 /* WaypointTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxDirections/AttributeOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public struct AttributeOptions: OptionSet, CustomStringConvertible {
extension AttributeOptions: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(description.components(separatedBy: ","))
try container.encode(description.components(separatedBy: ",").filter { !$0.isEmpty })
}

public init(from decoder: Decoder) throws {
Expand Down
24 changes: 18 additions & 6 deletions Sources/MapboxDirections/Directions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,16 @@ open class Directions: NSObject {
let result = try decoder.decode(RouteResponse.self, from: data)
guard (result.code == nil && result.message == nil) || result.code == "Ok" else {
let apiError = Directions.informativeError(code: result.code, message: result.message, response: response, underlyingError: possibleError)
completionHandler(nil, nil, apiError)
DispatchQueue.main.async {
completionHandler(nil, nil, apiError)
}
return
}

guard let routes = result.routes else {
completionHandler(result.waypoints, nil, .unableToRoute)
DispatchQueue.main.async {
completionHandler(result.waypoints, nil, .unableToRoute)
}
return
}

Expand Down Expand Up @@ -243,12 +247,16 @@ open class Directions: NSObject {
let result = try decoder.decode(MatchResponse.self, from: data)
guard result.code == "Ok" else {
let apiError = Directions.informativeError(code: result.code, message: result.message, response: response, underlyingError: possibleError)
completionHandler(nil, apiError)
DispatchQueue.main.async {
completionHandler(nil, apiError)
}
return
}

guard let matches = result.matches else {
completionHandler(nil, .unableToRoute)
DispatchQueue.main.async {
completionHandler(nil, .unableToRoute)
}
return
}

Expand Down Expand Up @@ -307,12 +315,16 @@ open class Directions: NSObject {
let result = try decoder.decode(MapMatchingResponse.self, from: data)
guard result.code == "Ok" else {
let apiError = Directions.informativeError(code: result.code, message:nil, response: response, underlyingError: possibleError)
completionHandler(nil, nil, apiError)
DispatchQueue.main.async {
completionHandler(nil, nil, apiError)
}
return
}

guard let routes = result.routes else {
completionHandler(result.waypoints, nil, .unableToRoute)
DispatchQueue.main.async {
completionHandler(result.waypoints, nil, .unableToRoute)
}
return
}

Expand Down
19 changes: 10 additions & 9 deletions Sources/MapboxDirections/DirectionsOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ open class DirectionsOptions: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(waypoints, forKey: .waypoints)
try container.encode(profileIdentifier.rawValue, forKey: .profileIdentifier)
try container.encode(profileIdentifier, forKey: .profileIdentifier)
try container.encode(includesSteps, forKey: .includesSteps)
try container.encode(shapeFormat, forKey: .shapeFormat)
try container.encode(routeShapeResolution, forKey: .routeShapeResolution)
try container.encode(attributeOptions, forKey: .attributeOptions)
try container.encode(locale, forKey: .locale)
try container.encode(locale.identifier, forKey: .locale)
try container.encode(includesSpokenInstructions, forKey: .includesSpokenInstructions)
try container.encode(distanceMeasurementSystem, forKey: .distanceMeasurementSystem)
try container.encode(includesVisualInstructions, forKey: .includesVisualInstructions)
Expand All @@ -168,7 +168,8 @@ open class DirectionsOptions: Codable {
shapeFormat = try container.decode(RouteShapeFormat.self, forKey: .shapeFormat)
routeShapeResolution = try container.decode(RouteShapeResolution.self, forKey: .routeShapeResolution)
attributeOptions = try container.decode(AttributeOptions.self, forKey: .attributeOptions)
locale = try container.decode(Locale.self, forKey: .locale)
let identifier = try container.decode(String.self, forKey: .locale)
locale = Locale(identifier: identifier)
includesSpokenInstructions = try container.decode(Bool.self, forKey: .includesSpokenInstructions)
distanceMeasurementSystem = try container.decode(MeasurementSystem.self, forKey: .distanceMeasurementSystem)
includesVisualInstructions = try container.decode(Bool.self, forKey: .includesVisualInstructions)
Expand Down Expand Up @@ -352,20 +353,20 @@ open class DirectionsOptions: Codable {
return queryItems
}

private var bearings: String? {
if waypoints.compactMap({ $0.heading }).isEmpty {
var bearings: String? {
guard waypoints.contains(where: { $0.heading ?? -1 >= 0 }) else {
return nil
}
return waypoints.map({ $0.headingDescription }).joined(separator: ";")
}

private var radiuses: String? {
guard !self.waypoints.filter({ $0.coordinateAccuracy != nil}).isEmpty else {
var radiuses: String? {
guard waypoints.contains(where: { $0.coordinateAccuracy ?? -1 >= 0 }) else {
return nil
}

let accuracies = self.waypoints.map { (waypoint) -> String in
guard let accuracy = waypoint.coordinateAccuracy else {
let accuracies = self.waypoints.map { (waypoint) -> String in
guard let accuracy = waypoint.coordinateAccuracy, accuracy >= 0 else {
return "unlimited"
}
return String(accuracy)
Expand Down
30 changes: 17 additions & 13 deletions Sources/MapboxDirections/DirectionsResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ open class DirectionsResult: Codable {

// MARK: Creating a Directions Result

init(legs: [RouteLeg], shape: LineString?, distance: CLLocationDistance, expectedTravelTime: TimeInterval, options: DirectionsOptions) {
self.legs = legs
self.shape = shape
self.distance = distance
self.expectedTravelTime = expectedTravelTime
_directionsOptions = options
}

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
legs = try container.decode([RouteLeg].self, forKey: .legs)
Expand Down Expand Up @@ -54,14 +62,10 @@ open class DirectionsResult: Codable {
apiEndpoint = try container.decodeIfPresent(URL.self, forKey: .apiEndpoint)
routeIdentifier = try container.decodeIfPresent(String.self, forKey: .routeIdentifier)

do {
speechLocale = try container.decodeIfPresent(Locale.self, forKey: .speechLocale)
} catch let DecodingError.typeMismatch(mismatchedType, context) {
guard mismatchedType == [String: Any].self else {
throw DecodingError.typeMismatch(mismatchedType, context)
}
let identifier = try container.decode(String.self, forKey: .speechLocale)
if let identifier = try container.decodeIfPresent(String.self, forKey: .speechLocale) {
speechLocale = Locale(identifier: identifier)
} else {
speechLocale = nil
}
}

Expand All @@ -77,15 +81,15 @@ open class DirectionsResult: Codable {
try container.encodeIfPresent(accessToken, forKey: .accessToken)
try container.encodeIfPresent(apiEndpoint, forKey: .apiEndpoint)
try container.encodeIfPresent(routeIdentifier, forKey: .routeIdentifier)
try container.encodeIfPresent(speechLocale, forKey: .speechLocale)
try container.encodeIfPresent(speechLocale?.identifier, forKey: .speechLocale)
}

// MARK: Getting the Shape of the Route

/**
An array of geographic coordinates defining the path of the route from start to finish.
The roads or paths taken as a contiguous polyline.
This array may be `nil` or simplified depending on the `DirectionsOptions.routeShapeResolution` property of the original `RouteOptions` or `MatchOptions` object.
The shape may be `nil` or simplified depending on the `DirectionsOptions.routeShapeResolution` property of the original `RouteOptions` or `MatchOptions` object.
Using the [Mapbox Maps SDK for iOS](https://docs.mapbox.com/ios/maps/) or [Mapbox Maps SDK for macOS](https://mapbox.github.io/mapbox-gl-native/macos/), you can create an `MGLPolyline` object using these coordinates to display an overview of the route on an `MGLMapView`.
*/
Expand All @@ -94,7 +98,7 @@ open class DirectionsResult: Codable {
// MARK: Getting the Legs Along the Route

/**
An array of `RouteLeg` objects representing the legs of the route.
The legs that are traversed in order.
The number of legs in this array depends on the number of waypoints. A route with two waypoints (the source and destination) has one leg, a route with three waypoints (the source, an intermediate waypoint, and the destination) has two legs, and so on.
Expand Down Expand Up @@ -131,7 +135,7 @@ open class DirectionsResult: Codable {
Do not assume that the user would travel along the route at a fixed speed. For more granular travel times, use the `RouteLeg.expectedTravelTime` or `RouteStep.expectedTravelTime`. For even more granularity, specify the `AttributeOptions.expectedTravelTime` option and use the `RouteLeg.expectedSegmentTravelTimes` property.
*/
public let expectedTravelTime: TimeInterval
open var expectedTravelTime: TimeInterval

// MARK: Configuring Speech Synthesis

Expand All @@ -145,7 +149,7 @@ open class DirectionsResult: Codable {
// MARK: Reproducing the Route

/**
`RouteOptions` used to create the directions request.
Criteria for reproducing this route.
The route options object’s profileIdentifier property reflects the primary mode of transportation used for the route. Individual steps along the route might use different modes of transportation as necessary.
*/
Expand Down
Loading

0 comments on commit 4d91bb2

Please sign in to comment.