funcload<T: Decodable>(_fileName: String) -> T { // The data value type allows simple byte buffers to take on behavior of Foundation objects. let data: Data guardlet file =Bundle.main.url(forResource: fileName, withExtension: nil) else { fatalError("Couldn't find \(fileName) in main bundle.") } do { data =tryData(contentsOf: file) } catch { fatalError("Couldn't load \(fileName) from main bundle:\n\(error)") } do { let decoder =JSONDecoder() returntry decoder.decode(T.self, from: data) } catch { fatalError("Couldn't parse \(fileName) as \(T.self):\n\(error)") } }
finalclassMapViewCoordinator: NSObject, MKMapViewDelegate { privatelet mapView: MapView init(_control: MapView) { self.mapView = control } funcmapView(_mapView: MKMapView, didAddviews: [MKAnnotationView]) { iflet annotationView = views.first, let annotation = annotationView.annotation { if annotation isMKUserLocation { let region =MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000) mapView.setRegion(region, animated: true) } } }
funcmapView(_mapView: MKMapView, rendererForoverlay: MKOverlay) -> MKOverlayRenderer { let renderer =MKPolylineRenderer(overlay: overlay) // set the line properties such as color and width renderer.strokeColor = .blue renderer.lineWidth =3.0 return renderer } }