TKRouter

Objective-C

@interface TKRouter : NSObject

Swift

class TKRouter : NSObject

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

  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) TripRequest *currentRequest

    Swift

    var currentRequest: TripRequest? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSSet <NSString *> *modeIdentifiers

    Swift

    var modeIdentifiers: Set<String>? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSSet <NSURLQueryItem *> *additionalParameters

    Swift

    var additionalParameters: Set<URLQueryItem>? { get set }
  • Optional server to use instead of TKServer.shared. Should only be used for testing or development.

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) TKServer *server;

    Swift

    var server: TKServer? { get set }
  • The main method to call to have the router calculate trips.

    Declaration

    Objective-C

    - (void)fetchTripsForRequest:(nonnull TripRequest *)request
                         success:(nonnull TKRouterSuccess)success
                         failure:(nonnull TKRouterError)failure;

    Swift

    func fetchTrips(for request: TripRequest, success: @escaping TKRouterSuccess, failure: @escaping TKRouterError)

    Parameters

    request

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

  • 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 TKUserProfileHelper for setting those.

    Declaration

    Objective-C

    - (NSUInteger)
        multiFetchTripsForRequest:(nonnull TripRequest *)request
                            modes:(nullable NSArray<NSString *> *)modes
                       classifier:(nullable id<TKTripClassifier>)classifier
                         progress:(nullable void (^)(NSUInteger))progress
                       completion:(nonnull void (^)(TripRequest *_Nonnull,
                                                    NSError *_Nullable))completion;

    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 TKUserProfileHelper 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.

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

    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

    Objective-C

    - (void)fetchBestTripForRequest:(nonnull TripRequest *)request
                            success:(nonnull TKRouterSuccess)success
                            failure:(nonnull TKRouterError)failure;

    Swift

    func fetchBestTrip(for request: TripRequest, success: @escaping TKRouterSuccess, failure: @escaping TKRouterError)
  • Undocumented

    Declaration

    Objective-C

    - (void)cancelRequests;

    Swift

    func cancelRequests()
  • Undocumented

    Declaration

    Objective-C

    - (void)downloadTrip:(NSURL *)url
      intoTripKitContext:(NSManagedObjectContext *)tripKitContext
              completion:(void(^)(Trip * __nullable trip))completion;

    Swift

    func downloadTrip(_ url: URL, intoTripKitContext tripKitContext: NSManagedObjectContext, completion: @escaping (Trip?) -> Void)
  • Undocumented

    Declaration

    Objective-C

    - (void)downloadTrip:(NSURL *)url
              identifier:(nullable NSString *)identifier
      intoTripKitContext:(NSManagedObjectContext *)tripKitContext
              completion:(void(^)(Trip * __nullable trip))completion;

    Swift

    func downloadTrip(_ url: URL, identifier: String?, intoTripKitContext tripKitContext: NSManagedObjectContext, completion: @escaping (Trip?) -> Void)
  • Undocumented

    Declaration

    Objective-C

    - (void)updateTrip:(Trip *)trip
            completion:(void(^)(Trip *trip))completion;

    Swift

    func update(_ trip: Trip, completion: @escaping (Trip) -> Void)
  • Undocumented

    Declaration

    Objective-C

    - (void)updateTrip:(Trip *)trip
    completionWithFlag:(void(^)(Trip *trip, BOOL tripUpdated))completion;

    Swift

    func update(_ trip: Trip, completionWithFlag completion: @escaping (Trip, Bool) -> Void)
  • Undocumented

    Declaration

    Objective-C

    - (void)updateTrip:(Trip *)trip
               fromURL:(NSURL *)URL
               aborter:(nullable BOOL(^)(NSURL *URL))aborter
            completion:(void(^)(NSURL *URL, Trip * __nullable trip, NSError * __nullable error))completion;

    Swift

    func update(_ trip: Trip, from URL: URL, aborter: ((URL) -> Bool)?, completion: @escaping (URL, Trip?, Error?) -> Void)
  • Undocumented

    Declaration

    Objective-C

    + (nullable NSString *)urlForRoutingRequest:(TripRequest *)tripRequest
                            withModeIdentifiers:(nullable NSSet<NSString *> *)modeIdentifiers;

    Swift

    class func url(forRoutingRequest tripRequest: TripRequest, withModeIdentifiers modeIdentifiers: Set<String>?) -> String?