diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc6812b6..cf18d7363 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes to Mapbox Directions for Swift +## v2.4.1 +* Fixed an issue that caused a compiler error when subclassing `RouteOptions`. ([#685](https://github.com/mapbox/mapbox-directions-swift/pull/685)) + ## v2.4.0 * Fixed a crash that occurred when `RouteOptions.roadClassesToAvoid` or `RouteOptions.roadClassesToAllow` properties contained multiple road classes. diff --git a/Sources/MapboxDirections/DirectionsOptions.swift b/Sources/MapboxDirections/DirectionsOptions.swift index db73ce58f..f4e11412e 100644 --- a/Sources/MapboxDirections/DirectionsOptions.swift +++ b/Sources/MapboxDirections/DirectionsOptions.swift @@ -218,6 +218,18 @@ open class DirectionsOptions: Codable { } } + /** + Initializes an options object for routes between the given waypoints and an optional profile identifier. + + Do not call `DirectionsOptions(waypoints:profileIdentifier:)` directly; instead call the corresponding initializer of `RouteOptions` or `MatchOptions`. + + - parameter waypoints: An array of `Waypoint` objects representing locations that the route should visit in chronological order. The array should contain at least two waypoints (the source and destination) and at most 25 waypoints. (Some profiles, such as `ProfileIdentifier.automobileAvoidingTraffic`, [may have lower limits](https://docs.mapbox.com/api/navigation/#directions).) + - parameter profileIdentifier: A string specifying the primary mode of transportation for the routes. `ProfileIdentifier.automobile` is used by default. + */ + public convenience init(waypoints: [Waypoint], profileIdentifier: ProfileIdentifier? = nil) { + self.init(waypoints: waypoints, profileIdentifier: profileIdentifier, queryItems: nil) + } + /** Creates new options object by deserializing given `url` diff --git a/Sources/MapboxDirections/MapMatching/MatchOptions.swift b/Sources/MapboxDirections/MapMatching/MatchOptions.swift index 1acec1443..a7b47730b 100644 --- a/Sources/MapboxDirections/MapMatching/MatchOptions.swift +++ b/Sources/MapboxDirections/MapMatching/MatchOptions.swift @@ -42,6 +42,16 @@ open class MatchOptions: DirectionsOptions { self.init(waypoints: waypoints, profileIdentifier: profileIdentifier, queryItems: queryItems) } + /** + Initializes a match options object for matching locations against the road network. + + - parameter waypoints: An array of `Waypoint` objects representing locations that the route should visit in chronological order. The array should contain at least two waypoints (the source and destination) and at most 25 waypoints. (Some profiles, such as `ProfileIdentifier.automobileAvoidingTraffic`, [may have lower limits](https://docs.mapbox.com/api/navigation/#directions).) + - parameter profileIdentifier: A string specifying the primary mode of transportation for the routes. `ProfileIdentifier.automobile` is used by default. + */ + public convenience init(waypoints: [Waypoint], profileIdentifier: ProfileIdentifier? = nil) { + self.init(waypoints: waypoints, profileIdentifier: profileIdentifier, queryItems: nil) + } + public required init(waypoints: [Waypoint], profileIdentifier: ProfileIdentifier? = nil, queryItems: [URLQueryItem]? = nil) { super.init(waypoints: waypoints, profileIdentifier: profileIdentifier, queryItems: queryItems) diff --git a/Sources/MapboxDirections/RouteOptions.swift b/Sources/MapboxDirections/RouteOptions.swift index 6f2ae888a..6a95c9c6a 100644 --- a/Sources/MapboxDirections/RouteOptions.swift +++ b/Sources/MapboxDirections/RouteOptions.swift @@ -98,6 +98,16 @@ open class RouteOptions: DirectionsOptions { self.arriveBy = arriveBy } } + + /** + Initializes a route options object for routes between the given waypoints and an optional profile identifier. + + - parameter waypoints: An array of `Waypoint` objects representing locations that the route should visit in chronological order. The array should contain at least two waypoints (the source and destination) and at most 25 waypoints. (Some profiles, such as `ProfileIdentifier.automobileAvoidingTraffic`, [may have lower limits](https://www.mapbox.com/api-documentation/#directions).) + - parameter profileIdentifier: A string specifying the primary mode of transportation for the routes. `ProfileIdentifier.automobile` is used by default. + */ + public convenience init(waypoints: [Waypoint], profileIdentifier: ProfileIdentifier? = nil) { + self.init(waypoints: waypoints, profileIdentifier: profileIdentifier, queryItems: nil) + } #if canImport(CoreLocation) /** diff --git a/Tests/MapboxDirectionsTests/RouteOptionsTests.swift b/Tests/MapboxDirectionsTests/RouteOptionsTests.swift index 9e5194a3b..6b42510ef 100644 --- a/Tests/MapboxDirectionsTests/RouteOptionsTests.swift +++ b/Tests/MapboxDirectionsTests/RouteOptionsTests.swift @@ -363,3 +363,11 @@ var testRouteOptions: RouteOptions { return opts } + +var routeOptionsSubclassTest = testRouteOptionsSubclass(waypoints: []) + +class testRouteOptionsSubclass: RouteOptions { + convenience init(waypoints: [Waypoint], profileIdentifier: ProfileIdentifier?) { + self.init(waypoints: [], profileIdentifier: nil, queryItems: nil) + } +}