0

I am a bit confused, possibly by XCode suggesting that I should have a third parameter for MKPolygon, or only 2 params when I at the third. I am sure it is something else small and silly in my formatting, but any help as to the best way to create an MKPolygon from an array of Coordinates would be wonderful!

// receive array of coordinates and update polygon of quarantine
func updateQuarantine(coords:[CLLocationCoordinate2D]) {

    let polyLine:MKPolygon = MKPolygon(coordinates: &coords, count: coords.count)           

    self.mapView.addOverlay(polyLine)  

    self.mapView.removeOverlay(quarantinePolygon)

    quarantinePolygon = polyLine
}
4

1 回答 1

1

To pass the in-out value &coords to MKPolygon(), the array has to be declared as a variable (var):

func updateQuarantine(var coords:[CLLocationCoordinate2D]) {
//             HERE ---^

    let polyLine = MKPolygon(coordinates: &coords, count: coords.count)

    // ...    
}

Function parameters are by default constant, i.e. as if they were defined with let.

于 2015-04-07T07:05:44.763 回答