TKRouter

@objc
public class TKRouter : NSObject

A TKRouter calculates trips for routing requests, it talks to TripGo’s routing.json API.

  • Undocumented

    See more

    Declaration

    Swift

    public enum RoutingError : Error, LocalizedError
  • Undocumented

    See more

    Declaration

    Swift

    public struct RoutingQuery
    extension TKRouter.RoutingQuery: TKRouterRequestable
  • Optional server to use instead of TKServer.shared.

    Declaration

    Swift

    public var server: TKServer?
  • Optional configuration parameters to use instead of TKSettings.Config.fromUserDefaults().

    Declaration

    Swift

    public var config: TKSettings.Config?
  • Set to limit the modes. If not provided, modes according to TKSettings will be used.

    Declaration

    Swift

    public var modeIdentifiers: Set<String>
  • A TKRouter might turn a routing request into multiple server requests. If some of these fail but others return trips, the default behaviour is to return the trips that were found without returning an error. Set this to true to always return an error if any of the requests fail, even if some trips were found by other requests.

    Declaration

    Swift

    public var failOnAnyError: Bool
  • The main method to call to have the router calculate trips.

    Declaration

    Swift

    public func fetchTrips(for request: TripRequest, additional: Set<URLQueryItem>? = nil, visibility: TripGroup.Visibility = .full, callbackQueue: DispatchQueue = .main, completion: @escaping (Result<Void, Error>) -> Void)

    Parameters

    request

    An instance of a TripRequest which specifies what kind of trips should get calculated.

    completion

    Block called when done, on success or failure

  • The main method to call to have the router calculate trips.

    Declaration

    Swift

    public func fetchTrips(for query: RoutingQuery, completion: @escaping (Result<TripRequest, Error>) -> Void)

    Parameters

    query

    An instance of a TripRequest which specifies what kind of trips should get calculated.

    completion

    Block called when done, on success or failure

  • Kicks off the server request to fetch the best trip matching the request and the enabled modes according to TKSettings.

    On success, the request’s .trips and .tripGroup properties will be set. Note, that these might include multiple trips (despite the naming of this method), which are variants of the same trip leaving earlier or later.

    Declaration

    Swift

    public func fetchBestTrip(for request: TKRouterRequestable, completion: @escaping (Result<Trip, Error>) -> Void)

    Parameters

    request

    The request specifying the query

    completion

    Callback executed when all requests have finished with the original request and, optionally, an error if all failed.

  • Undocumented

    Declaration

    Swift

    public func cancelRequests()

Multi-fetch

  • Kicks off the required server requests asynchronously to the servers, and returns the final result.

    Note

    Calling this method will lock-in the departure time for “Leave now” queries.

    As trips get added, they get flagged with full, minimised or hidden visibility. Which depends on the standard defaults. Check TKSettings for setting those.

    Declaration

    Swift

    public func multiFetchTrips(for query: RoutingQuery, classifier: TKTripClassifier? = nil) async throws -> TripRequest

    Parameters

    request

    The request specifying the query

    classifier

    Optional classifier to assign TripGroup‘s classification

    Return Value

    TripRequest with the resulting trip groups associated

  • Kicks off the required server requests asynchronously to the servers. As they return progress is called and the trips get added to TripKit’s database. Also calls completion when all are done.

    Note

    Calling this method will lock-in the departure time for “Leave now” queries.

    As trips get added, they get flagged with full, minimised or hidden visibility. Which depends on the standard defaults. Check TKSettings for setting those.

    Declaration

    Swift

    @discardableResult
    public func multiFetchTrips(for query: RoutingQuery, classifier: TKTripClassifier? = nil, progress: ((UInt) -> Void)? = nil, completion: @escaping (Result<TripRequest, Error>) -> Void) -> UInt

    Parameters

    request

    The request specifying the query

    classifier

    Optional classifier to assign TripGroup‘s classification

    progress

    Optional progress callback executed when each request finished, with the number of completed requests passed to the block.

    completion

    Callback executed when all requests have finished with the original request and, optionally, an error if all failed.

    Return Value

    The number of requests sent. This will match the number of times progress is called.

  • Kicks off the required server requests asynchronously to the servers. As they return progress is called and the trips get added to TripKit’s database. Also calls completion when all are done.

    Note

    Calling this method will lock-in the departure time for “Leave now” queries.

    As trips get added, they get flagged with full, minimised or hidden visibility. Which depends on the standard defaults. Check TKSettings for setting those.

    Declaration

    Swift

    @discardableResult
    public func multiFetchTrips(for request: TripRequest, modes: Set<String>? = nil, classifier: TKTripClassifier? = nil, progress: ((UInt) -> Void)? = nil, completion: @escaping (Result<Void, Error>) -> Void) -> UInt

    Parameters

    request

    The request specifying the query

    modes

    The modes to enable. If set to nil then it’ll use the modes as set in the user defaults (see TKSettings for more)

    classifier

    Optional classifier to assign TripGroup‘s classification

    progress

    Optional progress callback executed when each request finished, with the number of completed requests passed to the block.

    completion

    Callback executed when all requests have finished with the original request and, optionally, an error if all failed.

    Return Value

    The number of requests sent. This will match the number of times progress is called.

Hitting API