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

Provide convenience initializers for options #685

Closed
wants to merge 3 commits into from

Conversation

jill-cardamon
Copy link
Contributor

This PR fixes #684 by adding convenience initializers for RouteOptions, MatchOptions, and DirectionsOptions.

@jill-cardamon jill-cardamon requested a review from 1ec5 April 21, 2022 18:31
@jill-cardamon jill-cardamon self-assigned this Apr 21, 2022
/**
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`.
Copy link
Contributor Author

@jill-cardamon jill-cardamon Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since developers should not call DirectionsOptions(waypoints:profileIdentifier:) directly, is it safe to not include this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include it, because it is valid, if somewhat contrived, to subclass DirectionsOptions directly. The use case would be building support for another navigation API service endpoint. Normally that’s something this library would have built right in, but in principle, client code could implement that support all the same.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to add a changelog entry about fixing the incompatibility introduced in #655 by restoring these initializers.

/**
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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include it, because it is valid, if somewhat contrived, to subclass DirectionsOptions directly. The use case would be building support for another navigation API service endpoint. Normally that’s something this library would have built right in, but in principle, client code could implement that support all the same.

- 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s add a test that subclasses RouteOptions and overrides just this initializer, not init(waypoints:profileIdentifier:queryItems:). It doesn’t have to do anything; we just need to see if it would compile. I’m concerned that the required bit means it still needs to be implemented even if the convenience initializer would call the required one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it sufficient to subclass RouteOptions, override the convenience init, and initialize a RouteOptionsSubclass object through the override?

@jill-cardamon jill-cardamon requested a review from 1ec5 April 21, 2022 19:34

class testRouteOptionsSubclass: RouteOptions {
convenience init(waypoints: [Waypoint], profileIdentifier: ProfileIdentifier?) {
self.init(waypoints: [], profileIdentifier: nil, queryItems: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to match what NavigationRouteOptions was doing here more closely, so we can be sure the incompatibility is fixed?

https://github.com/mapbox/mapbox-navigation-ios/blob/v2.3.1/Sources/MapboxCoreNavigation/NavigationRouteOptions.swift#L20

Alternatively, you could try checking out navigation SDK v2.3.x and pointing it to this branch to see if it’ll compile. Thanks!

@jill-cardamon
Copy link
Contributor Author

This PR did not fix the stability issues with the Nav SDK. Instead, several patch releases of MapboxCoreNavigation were issued and can be found here: v2.1.2, v2.2.1, and v2.3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants