New Xcode beta new problems: MKGeodesicPolyline

核能气质少年 提交于 2020-01-03 16:45:14

问题


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.


回答1:


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




回答2:


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

  • remove "&" symbol before the coordinates . This solved the issue.


来源:https://stackoverflow.com/questions/38271927/new-xcode-beta-new-problems-mkgeodesicpolyline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!