Skip to content

Commit

Permalink
Fix swift 3.1 warnings (#119)
Browse files Browse the repository at this point in the history
* Fix swift 3.1 warnings

* Fixed warnings in test code

* Fail gracefully decoding invalid maneuver direction
  • Loading branch information
Bobby Sudekum committed Mar 30, 2017
1 parent b900f7e commit 9615a66
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MapboxDirections/MBIntersection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Intersection: NSObject, NSSecureCoding {
outletIndex = decoder.decodeInteger(forKey: "outletIndex")

approachLanes = decoder.decodeObject(of: [NSArray.self, Lane.self], forKey: "approachLanes") as? [Lane]
usableApproachLanes = decoder.decodeObject(of: NSIndexSet.self, forKey: "usableApproachLanes") as? IndexSet
usableApproachLanes = decoder.decodeObject(of: NSIndexSet.self, forKey: "usableApproachLanes") as IndexSet?
}

open static var supportsSecureCoding = true
Expand Down
6 changes: 4 additions & 2 deletions MapboxDirections/MBRouteStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,9 @@ open class RouteStep: NSObject, NSSecureCoding {
return nil
}
maneuverType = ManeuverType(description: maneuverTypeDescription)
let maneuverDirectionDescription = decoder.decodeObject(of: NSString.self, forKey: "maneuverDirection") as! String
guard let maneuverDirectionDescription = decoder.decodeObject(of: NSString.self, forKey: "maneuverDirection") as String? else {
return nil
}
maneuverDirection = ManeuverDirection(description: maneuverDirectionDescription)

if let maneuverLocationDictionary = decoder.decodeObject(of: [NSDictionary.self, NSString.self, NSNumber.self], forKey: "maneuverLocation") as? [String: CLLocationDegrees],
Expand All @@ -574,7 +576,7 @@ open class RouteStep: NSObject, NSSecureCoding {
expectedTravelTime = decoder.decodeDouble(forKey: "expectedTravelTime")
names = decoder.decodeObject(of: [NSArray.self, NSString.self], forKey: "names") as? [String]

guard let transportTypeDescription = decoder.decodeObject(of: NSString.self, forKey: "transportType") as? String else {
guard let transportTypeDescription = decoder.decodeObject(of: NSString.self, forKey: "transportType") as String? else {
return nil
}
transportType = TransportType(description: transportTypeDescription)
Expand Down
2 changes: 1 addition & 1 deletion MapboxDirections/MBWaypoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ open class Waypoint: NSObject, NSCopying, NSSecureCoding {
coordinateAccuracy = decoder.decodeDouble(forKey: "coordinateAccuracy")
heading = decoder.decodeDouble(forKey: "heading")
headingAccuracy = decoder.decodeDouble(forKey: "headingAccuracy")
name = decoder.decodeObject(of: NSString.self, forKey: "name") as? String
name = decoder.decodeObject(of: NSString.self, forKey: "name") as String?
}

open func encode(with coder: NSCoder) {
Expand Down
6 changes: 3 additions & 3 deletions MapboxDirectionsTests/Fixture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ internal class Fixture {
}
}

internal class func JSONFromFileNamed(name: String) -> [String: AnyObject] {
internal class func JSONFromFileNamed(name: String) -> [String: Any] {
guard let path = Bundle(for: self).path(forResource: name, ofType: "json") else {
XCTAssert(false, "Fixture \(name) not found.")
return [:]
}
guard let data = NSData(contentsOfFile: path) as? Data else {
guard let data = NSData(contentsOfFile: path) as Data? else {
XCTAssert(false, "No data found at \(path).")
return [:]
}
do {
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: AnyObject]
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
} catch {
XCTAssert(false, "Unable to decode JSON fixture at \(path): \(error).")
return [:]
Expand Down
4 changes: 2 additions & 2 deletions MapboxDirectionsTests/V4Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class V4Tests: XCTestCase {
options.includesAlternativeRoutes = true
var route: Route?
let task = Directions(accessToken: BogusToken).calculate(options) { (waypoints, routes, error) in
XCTAssertNil(error, "Error: \(error)")
XCTAssertNil(error, "Error: \(error!)")

XCTAssertNotNil(routes)
XCTAssertEqual(routes!.count, 2)
Expand All @@ -46,7 +46,7 @@ class V4Tests: XCTestCase {
XCTAssertNotNil(task)

waitForExpectations(timeout: 2) { (error) in
XCTAssertNil(error, "Error: \(error)")
XCTAssertNil(error, "Error: \(error!)")
XCTAssertEqual(task.state, .completed)
}

Expand Down
4 changes: 2 additions & 2 deletions MapboxDirectionsTests/V5Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class V5Tests: XCTestCase {
options.routeShapeResolution = .full
var route: Route?
let task = Directions(accessToken: BogusToken).calculate(options) { (waypoints, routes, error) in
XCTAssertNil(error, "Error: \(error)")
XCTAssertNil(error, "Error: \(error!)")

XCTAssertNotNil(routes)
XCTAssertEqual(routes!.count, 2)
Expand All @@ -48,7 +48,7 @@ class V5Tests: XCTestCase {
XCTAssertNotNil(task)

waitForExpectations(timeout: 2) { (error) in
XCTAssertNil(error, "Error: \(error)")
XCTAssertNil(error, "Error: \(error!)")
XCTAssertEqual(task.state, .completed)
}

Expand Down

0 comments on commit 9615a66

Please sign in to comment.