iosxcodegeodesic-sphere

New Xcode beta new problems: MKGeodesicPolyline


The brand new Xcode version, in addition to removing a wide nume of place where to add an empty function call, introduced a funny problem with an simple piece of code drawing a geodetic path:

func drawPolyline(from startLocation: CLLocation, endLocation:CLLocation) {
    let point1 = startLocation.coordinate
    let point2 = endLocation.coordinate
    var points: [CLLocationCoordinate2D]
    points = [point1, point2]
    var coordinates=points[0]
    let geodesic = MKGeodesicPolyline(coordinates: &coordinates, count:2)
    self.mapView.add(geodesic)
}

The compiler complaints about an:

Ambiguous use of 'init(coordinates:count:)'

When I try to click on the given options, I am always led to that line. I tried to clean the project to no avail.


Solution

  • In this case MKGeodesicPolyline would use either UnsafePointer or UnsafeMutablePointer using the type CLLocationCoordinate2D which you defined as points, so you'd likely want:

    let geodesic = MKGeodesicPolyline(coordinates: points, count: 2)
    

    Apple Developer : CLLocation