Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge profile identifier to Objective-C #106

Merged
merged 3 commits into from Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions MapboxDirections.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
358D48811E2EAB2500F32A65 /* MBRouteOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 358D48801E2EAB2500F32A65 /* MBRouteOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
358D48821E2EAB2500F32A65 /* MBRouteOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 358D48801E2EAB2500F32A65 /* MBRouteOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
358D48831E2EAB2500F32A65 /* MBRouteOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 358D48801E2EAB2500F32A65 /* MBRouteOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
358D48841E2EAB2500F32A65 /* MBRouteOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 358D48801E2EAB2500F32A65 /* MBRouteOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
358D48861E2EAB4500F32A65 /* MBRouteOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 358D48851E2EAB4500F32A65 /* MBRouteOptions.m */; };
358D48871E2EAB4500F32A65 /* MBRouteOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 358D48851E2EAB4500F32A65 /* MBRouteOptions.m */; };
358D48881E2EAB4500F32A65 /* MBRouteOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 358D48851E2EAB4500F32A65 /* MBRouteOptions.m */; };
358D48891E2EAB4500F32A65 /* MBRouteOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 358D48851E2EAB4500F32A65 /* MBRouteOptions.m */; };
C547EC691DB59F8F009817F3 /* MBLane.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57D55071DB58C0200B94B74 /* MBLane.swift */; };
C547EC6A1DB59F90009817F3 /* MBLane.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57D55071DB58C0200B94B74 /* MBLane.swift */; };
C547EC6B1DB59F91009817F3 /* MBLane.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57D55071DB58C0200B94B74 /* MBLane.swift */; };
Expand Down Expand Up @@ -117,6 +125,8 @@
C57B2E951DB8171300E9123A /* MBLaneIndication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBLaneIndication.h; sourceTree = "<group>"; };
C57D55001DB5669600B94B74 /* MBIntersection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBIntersection.swift; sourceTree = "<group>"; };
C57D55071DB58C0200B94B74 /* MBLane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBLane.swift; sourceTree = "<group>"; };
358D48801E2EAB2500F32A65 /* MBRouteOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBRouteOptions.h; sourceTree = "<group>"; };
358D48851E2EAB4500F32A65 /* MBRouteOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBRouteOptions.m; sourceTree = "<group>"; };
DA1A10AF1D00F8FF009F82FA /* MapboxDirections.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxDirections.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DA1A10B81D00F8FF009F82FA /* MapboxDirectionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxDirectionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DA1A10D51D0101ED009F82FA /* MapboxDirections.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxDirections.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -230,6 +240,8 @@
DD6254731AE70CB700017857 /* MBDirections.swift */,
DAC05F171CFC075300FA0071 /* MBRoute.swift */,
DAC05F191CFC077C00FA0071 /* MBRouteLeg.swift */,
358D48801E2EAB2500F32A65 /* MBRouteOptions.h */,
358D48851E2EAB4500F32A65 /* MBRouteOptions.m */,
DA2E03EA1CB0E13D00D1269A /* MBRouteOptions.swift */,
DA2E03E81CB0E0B000D1269A /* MBRouteStep.swift */,
C57D55001DB5669600B94B74 /* MBIntersection.swift */,
Expand Down Expand Up @@ -345,6 +357,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
358D48821E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA1A10C61D00F969009F82FA /* MapboxDirections.h in Headers */,
C57B2E971DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
Expand All @@ -354,6 +367,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
358D48831E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA1A10EC1D010247009F82FA /* MapboxDirections.h in Headers */,
C57B2E981DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
Expand All @@ -363,6 +377,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
358D48841E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA1A11031D0103A3009F82FA /* MapboxDirections.h in Headers */,
C57B2E991DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
Expand All @@ -372,6 +387,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
358D48811E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA6C9D8B1CAE442B00094FBC /* MapboxDirections.h in Headers */,
C57B2E961DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
Expand Down Expand Up @@ -641,6 +657,7 @@
buildActionMask = 2147483647;
files = (
DA1A10C91D00F969009F82FA /* MBRouteLeg.swift in Sources */,
358D48871E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DA1A10CC1D00F969009F82FA /* MBWaypoint.swift in Sources */,
DA1A10CA1D00F969009F82FA /* MBRouteOptions.swift in Sources */,
DA1A10C81D00F969009F82FA /* MBRoute.swift in Sources */,
Expand Down Expand Up @@ -669,6 +686,7 @@
buildActionMask = 2147483647;
files = (
DA1A10EF1D010247009F82FA /* MBRouteLeg.swift in Sources */,
358D48881E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DA1A10F21D010247009F82FA /* MBWaypoint.swift in Sources */,
DA1A10F01D010247009F82FA /* MBRouteOptions.swift in Sources */,
DA1A10EE1D010247009F82FA /* MBRoute.swift in Sources */,
Expand Down Expand Up @@ -697,6 +715,7 @@
buildActionMask = 2147483647;
files = (
DA1A11061D0103A3009F82FA /* MBRouteLeg.swift in Sources */,
358D48891E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DA1A11091D0103A3009F82FA /* MBWaypoint.swift in Sources */,
DA1A11071D0103A3009F82FA /* MBRouteOptions.swift in Sources */,
DA1A11051D0103A3009F82FA /* MBRoute.swift in Sources */,
Expand All @@ -713,6 +732,7 @@
buildActionMask = 2147483647;
files = (
DA2E03EB1CB0E13D00D1269A /* MBRouteOptions.swift in Sources */,
358D48861E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DAC05F161CFBFAC400FA0071 /* MBWaypoint.swift in Sources */,
C57D55081DB58C0200B94B74 /* MBLane.swift in Sources */,
DAC05F181CFC075300FA0071 /* MBRoute.swift in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions MapboxDirections/MBRoute.swift
Expand Up @@ -9,7 +9,7 @@ import Polyline
open class Route: NSObject, NSSecureCoding {
// MARK: Creating a Route

internal init(profileIdentifier: String, legs: [RouteLeg], distance: CLLocationDistance, expectedTravelTime: TimeInterval, coordinates: [CLLocationCoordinate2D]?) {
internal init(profileIdentifier: MBDirectionsProfileIdentifier, legs: [RouteLeg], distance: CLLocationDistance, expectedTravelTime: TimeInterval, coordinates: [CLLocationCoordinate2D]?) {
self.profileIdentifier = profileIdentifier
self.legs = legs
self.distance = distance
Expand All @@ -26,7 +26,7 @@ open class Route: NSObject, NSSecureCoding {
- parameter waypoints: An array of waypoints that the route visits in chronological order.
- parameter profileIdentifier: The profile identifier used to request the routes.
*/
public convenience init(json: [String: Any], waypoints: [Waypoint], profileIdentifier: String) {
public convenience init(json: [String: Any], waypoints: [Waypoint], profileIdentifier: MBDirectionsProfileIdentifier) {
// Associate each leg JSON with a source and destination. The sequence of destinations is offset by one from the sequence of sources.
let legInfo = zip(zip(waypoints.prefix(upTo: waypoints.endIndex - 1), waypoints.suffix(from: 1)),
json["legs"] as? [JSONDictionary] ?? [])
Expand Down Expand Up @@ -67,7 +67,7 @@ open class Route: NSObject, NSSecureCoding {
guard let decodedProfileIdentifier = decoder.decodeObject(of: NSString.self, forKey: "profileIdentifier") as String? else {
return nil
}
profileIdentifier = decodedProfileIdentifier
profileIdentifier = MBDirectionsProfileIdentifier(rawValue: decodedProfileIdentifier)
}

open static var supportsSecureCoding = true
Expand Down Expand Up @@ -160,13 +160,13 @@ open class Route: NSObject, NSSecureCoding {

The value of this property is `MBDirectionsProfileIdentifierAutomobile`, `MBDirectionsProfileIdentifierAutomobileAvoidingTraffic`, `MBDirectionsProfileIdentifierCycling`, or `MBDirectionsProfileIdentifierWalking`, depending on the `profileIdentifier` property of the original `RouteOptions` object. This property reflects the primary mode of transportation used for the route. Individual steps along the route might use different modes of transportation as necessary.
*/
open let profileIdentifier: String
open let profileIdentifier: MBDirectionsProfileIdentifier
}

// MARK: Support for Directions API v4

internal class RouteV4: Route {
convenience init(json: JSONDictionary, waypoints: [Waypoint], profileIdentifier: String) {
convenience init(json: JSONDictionary, waypoints: [Waypoint], profileIdentifier: MBDirectionsProfileIdentifier) {
let leg = RouteLegV4(json: json, source: waypoints.first!, destination: waypoints.last!, profileIdentifier: profileIdentifier)
let distance = json["distance"] as! Double
let expectedTravelTime = json["duration"] as! Double
Expand Down
10 changes: 5 additions & 5 deletions MapboxDirections/MBRouteLeg.swift
Expand Up @@ -9,7 +9,7 @@ import Polyline
open class RouteLeg: NSObject, NSSecureCoding {
// MARK: Creating a Leg

internal init(steps: [RouteStep], json: JSONDictionary, source: Waypoint, destination: Waypoint, profileIdentifier: String) {
internal init(steps: [RouteStep], json: JSONDictionary, source: Waypoint, destination: Waypoint, profileIdentifier: MBDirectionsProfileIdentifier) {
self.source = source
self.destination = destination
self.profileIdentifier = profileIdentifier
Expand All @@ -29,7 +29,7 @@ open class RouteLeg: NSObject, NSSecureCoding {
- parameter destination: The waypoint at the end of the leg.
- parameter profileIdentifier: The profile identifier used to request the routes.
*/
public convenience init(json: [String: Any], source: Waypoint, destination: Waypoint, profileIdentifier: String) {
public convenience init(json: [String: Any], source: Waypoint, destination: Waypoint, profileIdentifier: MBDirectionsProfileIdentifier) {
let steps = (json["steps"] as? [JSONDictionary] ?? []).map { RouteStep(json: $0) }
self.init(steps: steps, json: json, source: source, destination: destination, profileIdentifier: profileIdentifier)
}
Expand Down Expand Up @@ -58,7 +58,7 @@ open class RouteLeg: NSObject, NSSecureCoding {
guard let decodedProfileIdentifier = decoder.decodeObject(of: NSString.self, forKey: "profileIdentifier") as String? else {
return nil
}
profileIdentifier = decodedProfileIdentifier
profileIdentifier = MBDirectionsProfileIdentifier(rawValue: decodedProfileIdentifier)
}

open static var supportsSecureCoding = true
Expand Down Expand Up @@ -132,13 +132,13 @@ open class RouteLeg: NSObject, NSSecureCoding {

The value of this property is `MBDirectionsProfileIdentifierAutomobile`, `MBDirectionsProfileIdentifierAutomobileAvoidingTraffic`, `MBDirectionsProfileIdentifierCycling`, or `MBDirectionsProfileIdentifierWalking`, depending on the `profileIdentifier` property of the original `RouteOptions` object. This property reflects the primary mode of transportation used for the route leg. Individual steps along the route leg might use different modes of transportation as necessary.
*/
open let profileIdentifier: String
open let profileIdentifier: MBDirectionsProfileIdentifier
}

// MARK: Support for Directions API v4

internal class RouteLegV4: RouteLeg {
internal convenience init(json: JSONDictionary, source: Waypoint, destination: Waypoint, profileIdentifier: String) {
internal convenience init(json: JSONDictionary, source: Waypoint, destination: Waypoint, profileIdentifier: MBDirectionsProfileIdentifier) {
let steps = (json["steps"] as? [JSONDictionary] ?? []).map { RouteStepV4(json: $0) }
self.init(steps: steps, json: json, source: source, destination: destination, profileIdentifier: profileIdentifier)
}
Expand Down
38 changes: 38 additions & 0 deletions MapboxDirections/MBRouteOptions.h
@@ -0,0 +1,38 @@
#import <Foundation/Foundation.h>

#pragma mark - Specifying the Routing Profile

/**
Options determining the primary mode of transportation for the routes.
*/
typedef NSString * MBDirectionsProfileIdentifier NS_EXTENSIBLE_STRING_ENUM;

/**
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.
*/
extern MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierAutomobile;

/**
The returned directions are appropriate for driving or riding a car, truck, or motorcycle.

This profile avoids traffic congestion based on current traffic data. A driving route may use a ferry where necessary.

Where traffic data is absent, this profile prefers high-speed roads like highways, similar to `MBDirectionsProfileIdentifierAutomobile`.
*/
extern MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierAutomobileAvoidingTraffic;

/**
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.
*/
extern MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierCycling;

/**
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.
*/
extern MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierWalking;
7 changes: 7 additions & 0 deletions MapboxDirections/MBRouteOptions.m
@@ -0,0 +1,7 @@
#import "MBRouteOptions.h"


MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierAutomobile = @"mapbox/driving";
MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierAutomobileAvoidingTraffic = @"mapbox/driving-traffic";
MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierCycling = @"mapbox/cycling";
MBDirectionsProfileIdentifier const MBDirectionsProfileIdentifierWalking = @"mapbox/walking";