You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now all methods in Directions class return URLSessionDataTask instance directly. This makes subclassing Directions harder, as it leaks internal implementation of it (i.e. it uses URLSession underneath). As far as I noticed, returned tasks are only used for cancelling them, so it is possible to just introduce Cancellable protocol in form of:
publicprotocolCancellable{func cancel()}
with extension for URLSessionDataTask:
extensionURLSessionDataTask:Cancellable{}
and declare all methods to return it instead of URLSessionDataTask. This will allow to make subclasses of Directions (e.g. one using other web service than Mapbox's one or some offline solution) without being tied to URLSession.
The text was updated successfully, but these errors were encountered:
This will allow to make subclasses of Directions (e.g. one using other web service than Mapbox's one or some offline solution) without being tied to URLSession.
As a workaround for now, you can call that subclass’s url(forCalculating:) or urlRequest(forCalculating:), pass the return value into your third-party networking library, and transform the resulting data into a RouteResponse using JSONDecoder. Historically, url(forCalculating:) was this library’s answer for using a third-party library, but a protocol would make the library more flexible.
1ec5
added
the
op-ex
Refactoring, Tech Debt or any other operational excellence work.
label
Sep 25, 2020
Right now all methods in Directions class return
URLSessionDataTask
instance directly. This makes subclassing Directions harder, as it leaks internal implementation of it (i.e. it uses URLSession underneath). As far as I noticed, returned tasks are only used for cancelling them, so it is possible to just introduceCancellable
protocol in form of:with extension for
URLSessionDataTask
:and declare all methods to return it instead of
URLSessionDataTask
. This will allow to make subclasses of Directions (e.g. one using other web service than Mapbox's one or some offline solution) without being tied to URLSession.The text was updated successfully, but these errors were encountered: