mapbox / mapbox-directions-swift

Traffic-aware directions and map matching in Swift on iOS, macOS, tvOS, watchOS, and Linux
https://www.mapbox.com/navigation/
ISC License
181 stars 87 forks source link

Making `RouteResponse` `Equatable` and the `identifier/uuid` value #731

Closed sundeepgupta closed 1 year ago

sundeepgupta commented 1 year ago

What is the suggested approach to making RouteResponse Equatable?

Would it make sense to simply compare its identifier, which is the uuid in the Directions.calculate JSON payload?

Is this field ever expected to be nil?

jill-cardamon commented 1 year ago

Hi @sundeepgupta! To make RouteResponse truly Equatable, you would need to extend RouteResponse (and its affiliated properties that also aren't Equatable) to conform to the Equatable protocol. I would not recommend comparing only the identifiers since it isn't guaranteed that you can reliably distinguish responses solely on that property. However, comparing other properties in the response should work.

sundeepgupta commented 1 year ago

Hi @jill-cardamon, thanks for the reply. Understood - I will look into your suggestion.

Can you tell me more about the identifier and what it represents? Also, the Swift code declares it optional. Under what scenario is it expected to be nil?

jill-cardamon commented 1 year ago

@sundeepgupta Of course. The identifier is generated by the Directions API and represents a unique ID for the request. Every response should have a different value.

The identifier (in the Directions response itself) should always be populated with something, but the exceptions for a RouteResponse object are initializing a RouteResponse object from a MapMatchingResponse and potentially offline generated routes (I can clarify this case). We also don't provide an identifier when initializing a RouteResponse in some of our tests.

sundeepgupta commented 1 year ago

Thanks. If I understand correctly, if RouteResponse is created via Directions.calculate(... which makes an HTTP request to the Directions API, identifier will always be present. Correct?

jill-cardamon commented 1 year ago

Yes it should always be present in that case.

sundeepgupta commented 1 year ago

Thank you