@@ -209,30 +209,19 @@ open class Geocoder: NSObject {
209209 open func batchGeocode< T: GeocodeOptions > ( _ options: T , completionHandler: @escaping BatchCompletionHandler ) -> URLSessionDataTask where T: BatchGeocodeOptions {
210210 let url = urlForGeocoding ( options)
211211
212- // TODO: Migrate to Codable
213-
214- // let task = dataTaskWithURL(url, completionHandler: { (json) in
215- // let featureCollections = json as! [JSONDictionary]
216- // let placemarksByQuery = featureCollections.map { (featureCollection) -> [GeocodedPlacemark] in
217- // assert(featureCollection["type"] as? String == "FeatureCollection")
218- // let features = featureCollection["features"] as! [JSONDictionary]
219- // return features.flatMap { GeocodedPlacemark(featureJSON: $0) }
220- // }
221- // let attributionsByQuery = featureCollections.map { $0["attribution"] as! String }
222- // completionHandler(placemarksByQuery, attributionsByQuery, nil)
223- // }) { (error) in
224- // completionHandler(nil, nil, error)
225- // }
226-
227212 let task = dataTaskWithURL ( url, completionHandler: { ( data) in
228- // let featureCollections = data as! [JSONDictionary]
229- // let placemarksByQuery = featureCollections.map { (featureCollection) -> [GeocodedPlacemark] in
230- // assert(featureCollection["type"] as? String == "FeatureCollection")
231- // let features = featureCollection["features"] as! [JSONDictionary]
232- // return features.flatMap { GeocodedPlacemark(featureJSON: $0) }
233- // }
234- // let attributionsByQuery = featureCollections.map { $0["attribution"] as! String }
213+ guard let data = data else { return }
214+ let decoder = JSONDecoder ( )
235215
216+ do {
217+ let result = try decoder. decode ( [ GeocodeResult ] . self, from: data)
218+ let placemarks = result. map { $0. placemarks }
219+ let attributionsByQuery = result. map { $0. attribution }
220+ completionHandler ( placemarks, attributionsByQuery, nil )
221+
222+ } catch {
223+ completionHandler ( nil , nil , error as NSError )
224+ }
236225
237226 } ) { ( error) in
238227 completionHandler ( nil , nil , error)
0 commit comments