Skip to content

Commit

Permalink
Merge pull request #382 from mapbox/jerrad/objc-delenda-est
Browse files Browse the repository at this point in the history
Remove Objective-C compatibility; adopt Swift language features
  • Loading branch information
1ec5 authored Dec 11, 2019
2 parents 702ed4e + 87f6a96 commit f2841b6
Show file tree
Hide file tree
Showing 108 changed files with 5,358 additions and 6,009 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,32 @@

## master

### Packaging

* This library now requires a minimum deployment target of iOS 10.0 or above, macOS 10.12.0 or above, tvOS 10.0 or above, or watchOS 3.0 or above. Older operating system versions are no longer supported. ([#379](https://github.com/mapbox/MapboxDirections.swift/pull/379))
* Swift is now required to directly use public types and methods defined by this library. If your application is written in Objective-C or Cocoa-AppleScript, you need to implement your own wrapper in Swift that bridges to Objective-C. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* This library now depends on [Turf](https://github.com/mapbox/turf-swift/). ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))

### Error handling

* The `RouteCompletionHandler` and `MatchCompletionHandler` closures’ `error` argument is now a `DirectionsError` instead of an `NSError`. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Classes such as `Route`, `Match`, and `RouteStep` conform to the `Codable` protocol, so you can create instances of them from JSON-formatted `Data` using `JSONDecoder` and round-trip them back to JSON using `JSONEncoder`. Malformed input now throws decoding errors instead of crashing by unwrapping `nil`s. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))

### Visual instructions

* Removed the `Lane` class in favor of storing an array of `LaneIndication`s directly in the `Intersection.approachLanes` property. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Removed the `ComponentRepresentable` protocol, `VisualInstructionComponent` class, and `LaneIndicationComponent` class in favor of a `VisualInstruction.Component` enumeration that contains a `VisualInstruction.Component.TextRepresentation` and/or `VisualInstruction.Component.ImageRepresentation`, depending on the type of component. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Added the `VisualInstruction.Component.ImageRepresentation.imageURL(scale:format:)` method for fetching images with scales other than the current screen’s native scale or formats other than PNG. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))

### Other changes

* Removed support for [Mapbox Directions API v4](https://docs.mapbox.com/api/legacy/directions-v4/). ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Replaced the `MBDefaultWalkingSpeed`, `MBMinimumWalkingSpeed`, and `MBMaximumWalkingSpeed` constants with `CLLocationSpeed.normalWalking`, `CLLocationSpeed.minimumWalking`, and `CLLocationSpeed.maximumWalking`, respectively.
* Replaced the `Route.coordinates` property with `Route.shape` and the `RouteStep.coordinates` property with `RouteStep.shape`. The `Route.coordinateCount` and `RouteStep.coordinateCount` properties have been removed, but you can use the `LineString.coordinates` property to get the array of `CLLocationCoordinate2D`s. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* `RouteLeg.source` and `RouteLeg.destination` are now optional. They can be `nil` when the `RouteLeg` object is decoded individually from JSON. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Removed `TransportType.none`, `ManeuverType.none`, and `ManeuverDirection.none`. Unrecognized `TransportType` and `ManeuverDirection` values now raise decoding errors. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* `RouteStep.maneuverType` is now optional. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))
* Renamed the `Tracepoint.alternateCount` property to `Tracepoint.countOfAlternatives`. ([#382](https://github.com/mapbox/MapboxDirections.swift/pull/382))

## v0.30.0

Expand Down
1 change: 1 addition & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "raphaelmor/Polyline" ~> 4.2
github "mapbox/turf-swift" ~> 0.3
3 changes: 2 additions & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "4.11.1"
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "4.11.2"
github "linksmt/OHHTTPStubs" "563f48d3fab84ef04639649c770b00f4fa502cca"
github "mapbox/turf-swift" "v0.3.0"
github "raphaelmor/Polyline" "v4.2.1"
7 changes: 0 additions & 7 deletions Directions Example/AppDelegate.h

This file was deleted.

14 changes: 0 additions & 14 deletions Directions Example/AppDelegate.m

This file was deleted.

4 changes: 2 additions & 2 deletions Directions Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<string>44</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Use the user location to fetch a route from their current position.</string>
<key>UILaunchStoryboardName</key>
<string>Launch Screen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand All @@ -41,7 +43,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Use the user location to fetch a route from their current position.</string>
</dict>
</plist>
1 change: 0 additions & 1 deletion Directions Example/MBDrawingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public protocol MBDrawingViewDelegate: class {
}

public class MBDrawingView: UIView {

private var points: [CGPoint]!
private var context: CGContext!
private var strokeColor = UIColor.blue.withAlphaComponent(0.75) {
Expand Down
5 changes: 0 additions & 5 deletions Directions Example/ViewController.h

This file was deleted.

75 changes: 0 additions & 75 deletions Directions Example/ViewController.m

This file was deleted.

44 changes: 30 additions & 14 deletions Directions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ class ViewController: UIViewController, MBDrawingViewDelegate {
func setupDirections() {
let wp1 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.9131752, longitude: -77.0324047), name: "Mapbox")
let wp2 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), name: "White House")
wp1.allowsArrivingOnOppositeSide = false
wp2.allowsArrivingOnOppositeSide = false
let options = RouteOptions(waypoints: [wp1, wp2])
options.includesSteps = true

Directions.shared.calculate(options) { (waypoints, routes, error) in
guard error == nil else {
print("Error calculating directions: \(error!)")
if let error = error {
print("Error calculating directions: \(error)")
return
}

Expand All @@ -96,14 +94,16 @@ class ViewController: UIViewController, MBDrawingViewDelegate {
}
}

if route.coordinateCount > 0 {
if var routeCoordinates = route.shape?.coordinates, routeCoordinates.count > 0 {
// Convert the route’s coordinates into a polyline.
var routeCoordinates = route.coordinates!
let routeLine = MGLPolyline(coordinates: &routeCoordinates, count: route.coordinateCount)

// Add the polyline to the map and fit the viewport to the polyline.
let routeLine = MGLPolyline(coordinates: &routeCoordinates, count: UInt(routeCoordinates.count))

// Add the polyline to the map.
self.mapView.addAnnotation(routeLine)
self.mapView.setVisibleCoordinates(&routeCoordinates, count: route.coordinateCount, edgePadding: .zero, animated: true)

// Fit the viewport to the polyline.
let camera = self.mapView.cameraThatFitsShape(routeLine, direction: 0, edgePadding: .zero)
self.mapView.setCamera(camera, animated: true)
}
}
}
Expand All @@ -123,8 +123,16 @@ class ViewController: UIViewController, MBDrawingViewDelegate {
}

func drawingView(drawingView: MBDrawingView, didDrawWithPoints points: [CGPoint]) {
guard points.count > 0 else { return }

let coordinates = points.map {
let ratio: Double = Double(points.count) / 100.0
let keepEvery = Int(ratio.rounded(.up))

let abridgedPoints = points.enumerated().compactMap { index, element -> CGPoint? in
guard index % keepEvery == 0 else { return nil }
return element
}
let coordinates = abridgedPoints.map {
mapView.convert($0, toCoordinateFrom: mapView)
}
makeMatchRequest(locations: coordinates)
Expand All @@ -135,7 +143,14 @@ class ViewController: UIViewController, MBDrawingViewDelegate {

Directions.shared.calculate(matchOptions) { (matches, error) in
if let error = error {
print(error.localizedDescription)
let errorString = """
⚠️ Error Enountered. ⚠️
Failure Reason: \(error.failureReason ?? "")
Recovery Suggestion: \(error.recoverySuggestion ?? "")
Technical Details: \(error)
"""
print(errorString)
return
}

Expand All @@ -145,8 +160,9 @@ class ViewController: UIViewController, MBDrawingViewDelegate {
self.mapView.removeAnnotations(annotations)
}

var routeCoordinates = match.coordinates!
let routeLine = MGLPolyline(coordinates: &routeCoordinates, count: match.coordinateCount)
var routeCoordinates = match.shape!.coordinates
let coordCount = UInt(routeCoordinates.count)
let routeLine = MGLPolyline(coordinates: &routeCoordinates, count: coordCount)
self.mapView.addAnnotation(routeLine)
self.drawingView?.reset()
}
Expand Down
9 changes: 0 additions & 9 deletions Directions Example/main.m

This file was deleted.

4 changes: 2 additions & 2 deletions MapboxDirections.swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ Pod::Spec.new do |s|

# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.source_files = ["Sources/MapboxDirections", "Sources/MapboxDirections/*/*", "Sources/CMapboxDirections", "Sources/CMapboxDirections/*/*"]
s.exclude_files = ["Sources/CMapboxDirections/CMapboxDirections.h"]
s.source_files = ["Sources/MapboxDirections", "Sources/MapboxDirections/*/*"]

# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

Expand All @@ -47,5 +46,6 @@ Pod::Spec.new do |s|
s.swift_version = "5.0"

s.dependency "Polyline", "~> 4.2"
s.dependency "Turf", "~> 0.3"

end
Loading

0 comments on commit f2841b6

Please sign in to comment.