From e556d6e9f650f58b3e8a4c262c2a23eb54e8c3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 24 Dec 2019 16:02:58 -0800 Subject: [PATCH] Fixed map matching response decoding --- Sources/MapboxDirections/MapMatching/MapMatchingResponse.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/MapboxDirections/MapMatching/MapMatchingResponse.swift b/Sources/MapboxDirections/MapMatching/MapMatchingResponse.swift index e44c844c6..6bb2c6c8b 100644 --- a/Sources/MapboxDirections/MapMatching/MapMatchingResponse.swift +++ b/Sources/MapboxDirections/MapMatching/MapMatchingResponse.swift @@ -19,7 +19,8 @@ extension MapMatchingResponse: Decodable { routes = try container.decodeIfPresent([Route].self, forKey: .matches) // Decode waypoints from the response and update their names according to the waypoints from DirectionsOptions.waypoints. - let decodedWaypoints = try container.decode([Waypoint].self, forKey: .tracepoints) + // Map Matching API responses can contain null tracepoints. Null tracepoints can’t correspond to waypoints, so they’re irrelevant to the decoded structure. + let decodedWaypoints = try container.decode([Waypoint?].self, forKey: .tracepoints).compactMap { $0 } if let options = decoder.userInfo[.options] as? DirectionsOptions { // The response lists the same number of tracepoints as the waypoints in the request, whether or not a given waypoint is leg-separating. waypoints = zip(decodedWaypoints, options.waypoints).map { (pair) -> Waypoint in