Skip to content

Commit

Permalink
Finishing up. Only remaining thing to do is replace NSSecureCoding
Browse files Browse the repository at this point in the history
…behavior with `Codable`, which is in-flight in #221.
  • Loading branch information
Jerrad Thramer authored and 1ec5 committed Nov 2, 2019
1 parent c1aad9d commit a4a78e7
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 215 deletions.
30 changes: 18 additions & 12 deletions Sources/MapboxDirections/DirectionsProfileIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ The returned directions are appropriate for driving or riding a car, truck, or m
This profile prioritizes fast routes by preferring high-speed roads like highways. A driving route may use a ferry where necessary.
*/
public struct DirectionsProfileIdentifier: RawRepresentable {
public init?(rawValue: String) {
public struct DirectionsProfileIdentifier: Equatable, Hashable, RawRepresentable, ExpressibleByStringLiteral {
public typealias StringLiteralType = String
public typealias RawValue = String

public init(stringLiteral value: Self.StringLiteralType) {
self.init(rawValue: value)
}

public init(rawValue: String) {
self.rawValue = rawValue
}

public var rawValue: String

public typealias RawValue = String

/**
The returned directions are appropriate for driving or riding a car, truck, or motorcycle.
This profile prioritizes fast routes by preferring high-speed roads like highways. A driving route may use a ferry where necessary.
*/
static let automobile: String = "mapbox/driving"
public static let automobile: DirectionsProfileIdentifier = "mapbox/driving"

/**
The returned directions are appropriate for driving or riding a car, truck, or motorcycle.
Expand All @@ -32,36 +38,36 @@ public struct DirectionsProfileIdentifier: RawRepresentable {
Traffic data is available in [a number of countries and territories worldwide](https://docs.mapbox.com/help/how-mapbox-works/directions/#traffic-data). Where traffic data is unavailable, this profile prefers high-speed roads like highways, similar to `DirectionsProfileIdentifier.Automobile`.
*/
static let automobileAvoidingTraffic: String = "mapbox/driving-traffic"
public static let automobileAvoidingTraffic: DirectionsProfileIdentifier = "mapbox/driving-traffic"

/**
The returned directions are appropriate for riding a bicycle.
This profile prioritizes short, safe routes by avoiding highways and preferring cycling infrastructure, such as bike lanes on surface streets. A cycling route may, where necessary, use other modes of transportation, such as ferries or trains, or require dismounting the bicycle for a distance.
*/
static let cycling: String = "mapbox/cycling"
public static let cycling: DirectionsProfileIdentifier = "mapbox/cycling"

/**
The returned directions are appropriate for walking or hiking.
This profile prioritizes short routes, making use of sidewalks and trails where available. A walking route may use other modes of transportation, such as ferries or trains, where necessary.
*/
static let walking: String = "mapbox/walking"
public static let walking: DirectionsProfileIdentifier = "mapbox/walking"
}

@available(*, deprecated, renamed: "DirectionsPriority")
public typealias MBDirectionsPriority = DirectionsPriority

public struct DirectionsPriority: RawRepresentable {
public init?(rawValue: Double) {
public struct DirectionsPriority: Equatable, Hashable, RawRepresentable {
public init(rawValue: Double) {
self.rawValue = rawValue
}

public var rawValue: Double

public typealias RawValue = Double

static let low = -1.0
static let `default` = 0.0
static let high = 1.0
static let low = DirectionsPriority(rawValue: -1.0)
static let `default` = DirectionsPriority(rawValue: 0.0)
static let high = DirectionsPriority(rawValue: 1.0)
}
2 changes: 1 addition & 1 deletion Sources/MapboxDirections/MBComponentRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import Foundation
/**
The component representable protocol that comprises what the instruction banner should display.
*/
@objc(MBComponentRepresentable)

public protocol ComponentRepresentable: class, NSSecureCoding { }
2 changes: 1 addition & 1 deletion Sources/MapboxDirections/MBCongestion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
/**
A `CongestionLevel` indicates the level of traffic congestion along a road segment relative to the normal flow of traffic along that segment. You can color-code a route line according to the congestion level along each segment of the route.
*/
@objc(MBCongestionLevel)

public enum CongestionLevel: Int, CustomStringConvertible {
/**
There is not enough data to determine the level of congestion along the road segment.
Expand Down
11 changes: 4 additions & 7 deletions Sources/MapboxDirections/MBCoordinateBounds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import CoreLocation
/**
A bounding box represents a geographic region.
*/
@objc(MBCoordinateBounds)

public class CoordinateBounds: NSObject, Codable {
let southWest: CLLocationCoordinate2D
let northEast: CLLocationCoordinate2D

/**
Initializes a `BoundingBox` with known bounds.
*/
@objc
public init(southWest: CLLocationCoordinate2D, northEast: CLLocationCoordinate2D) {
public init(southWest: CLLocationCoordinate2D, northEast: CLLocationCoordinate2D) {
self.southWest = southWest
self.northEast = northEast
super.init()
Expand All @@ -22,8 +21,7 @@ public class CoordinateBounds: NSObject, Codable {
/**
Initializes a `BoundingBox` with known bounds.
*/
@objc
public init(northWest: CLLocationCoordinate2D, southEast: CLLocationCoordinate2D) {
public init(northWest: CLLocationCoordinate2D, southEast: CLLocationCoordinate2D) {
self.southWest = CLLocationCoordinate2D(latitude: southEast.latitude, longitude: northWest.longitude)
self.northEast = CLLocationCoordinate2D(latitude: northWest.latitude, longitude: southEast.longitude)
super.init()
Expand All @@ -32,8 +30,7 @@ public class CoordinateBounds: NSObject, Codable {
/**
Initializes a `BoundingBox` from an array of `CLLocationCoordinate2D`’s.
*/
@objc
convenience public init(coordinates: [CLLocationCoordinate2D]) {
convenience public init(coordinates: [CLLocationCoordinate2D]) {
assert(coordinates.count >= 2, "coordinates must consist of at least two coordinates")

var maximumLatitude: CLLocationDegrees = -90
Expand Down
24 changes: 12 additions & 12 deletions Sources/MapboxDirections/MBDirections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let userAgent: String = {
Each result produced by the directions object is stored in a `Route` object. Depending on the `RouteOptions` object you provide, each route may include detailed information suitable for turn-by-turn directions, or it may include only high-level information such as the distance, estimated travel time, and name of each leg of the trip. The waypoints that form the request may be conflated with nearby locations, as appropriate; the resulting waypoints are provided to the closure.
*/
@objc(MBDirections)

open class Directions: NSObject {
/**
A closure (block) to be called when a directions request is complete.
Expand Down Expand Up @@ -96,26 +96,26 @@ open class Directions: NSObject {
To use this object, a Mapbox [access token](https://docs.mapbox.com/help/glossary/access-token/) should be specified in the `MGLMapboxAccessToken` key in the main application bundle’s Info.plist.
*/
@objc(sharedDirections)

public static let shared = Directions(accessToken: nil)

/**
The API endpoint to use when requesting directions.
*/
@objc public private(set) var apiEndpoint: URL
public private(set) var apiEndpoint: URL

/**
The Mapbox access token to associate with the request.
*/
@objc public let accessToken: String
public let accessToken: String

/**
Initializes a newly created directions object with an optional access token and host.
- parameter accessToken: A Mapbox [access token](https://docs.mapbox.com/help/glossary/access-token/). If an access token is not specified when initializing the directions object, it should be specified in the `MGLMapboxAccessToken` key in the main application bundle’s Info.plist.
- parameter host: An optional hostname to the server API. The [Mapbox Directions API](https://docs.mapbox.com/api/navigation/#directions) endpoint is used by default.
*/
@objc public init(accessToken: String?, host: String?) {
public init(accessToken: String?, host: String?) {
let accessToken = accessToken ?? defaultAccessToken
assert(accessToken != nil && !accessToken!.isEmpty, "A Mapbox access token is required. Go to <https://account.mapbox.com/access-tokens/>. In Info.plist, set the MGLMapboxAccessToken key to your access token, or use the Directions(accessToken:host:) initializer.")

Expand All @@ -139,7 +139,7 @@ open class Directions: NSObject {
- parameter accessToken: A Mapbox [access token](https://docs.mapbox.com/help/glossary/access-token/). If an access token is not specified when initializing the directions object, it should be specified in the `MGLMapboxAccessToken` key in the main application bundle’s Info.plist.
*/
@objc public convenience init(accessToken: String?) {
public convenience init(accessToken: String?) {
self.init(accessToken: accessToken, host: nil)
}

Expand All @@ -156,7 +156,7 @@ open class Directions: NSObject {
- parameter completionHandler: The closure (block) to call with the resulting routes. This closure is executed on the application’s main thread.
- returns: The data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel this task.
*/
@objc(calculateDirectionsWithOptions:completionHandler:)

@discardableResult open func calculate(_ options: RouteOptions, completionHandler: @escaping RouteCompletionHandler) -> URLSessionDataTask {
let fetchStartDate = Date()
let task = dataTask(forCalculating: options, completionHandler: { (json) in
Expand Down Expand Up @@ -184,7 +184,7 @@ open class Directions: NSObject {
- parameter completionHandler: The closure (block) to call with the resulting matches. This closure is executed on the application’s main thread.
- returns: The data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting matches, cancel this task.
*/
@objc(calculateMatchesWithOptions:completionHandler:)

@discardableResult open func calculate(_ options: MatchOptions, completionHandler: @escaping MatchCompletionHandler) -> URLSessionDataTask {
let fetchStartDate = Date()
let task = dataTask(forCalculating: options, completionHandler: { (json) in
Expand Down Expand Up @@ -212,7 +212,7 @@ open class Directions: NSObject {
- parameter completionHandler: The closure (block) to call with the resulting routes. This closure is executed on the application’s main thread.
- returns: The data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel this task.
*/
@objc(calculateRoutesMatchingOptions:completionHandler:)

@discardableResult open func calculateRoutes(matching options: MatchOptions, completionHandler: @escaping RouteCompletionHandler) -> URLSessionDataTask {
let fetchStartDate = Date()
let task = dataTask(forCalculating: options, completionHandler: { (json) in
Expand Down Expand Up @@ -274,7 +274,7 @@ open class Directions: NSObject {
- parameter options: A `DirectionsOptions` object specifying the requirements for the resulting routes.
- returns: The URL to send the request to.
*/
@objc(URLForCalculatingDirectionsWithOptions:)

open func url(forCalculating options: DirectionsOptions) -> URL {
return url(forCalculating: options, httpMethod: "GET")
}
Expand All @@ -290,7 +290,7 @@ open class Directions: NSObject {
- parameter httpMethod: The HTTP method to use. The value of this argument should match the `URLRequest.httpMethod` of the request you send. Currently, only GET and POST requests are supported by the API.
- returns: The URL to send the request to.
*/
@objc(URLForCalculatingDirectionsWithOptions:HTTPMethod:)

open func url(forCalculating options: DirectionsOptions, httpMethod: String) -> URL {
let includesQuery = httpMethod != "POST"
var params = (includesQuery ? options.urlQueryItems : [])
Expand All @@ -316,7 +316,7 @@ open class Directions: NSObject {
- parameter options: A `DirectionsOptions` object specifying the requirements for the resulting routes.
- returns: A GET or POST HTTP request to calculate the specified options.
*/
@objc(URLRequestForCalculatingDirectionsWithOptions:)

open func urlRequest(forCalculating options: DirectionsOptions) -> URLRequest {
let getURL = self.url(forCalculating: options, httpMethod: "GET")
var request = URLRequest(url: getURL)
Expand Down
Loading

0 comments on commit a4a78e7

Please sign in to comment.