2015-04-07 36 views
0

我有點困惑,可能是XCode提示我應該爲MKPolygon提供第三個參數,或者當我在第三個參數時只有2個參數。我確信在格式化過程中它是一些小而愚蠢的東西,但是從座標陣列創建MKPolygon的最佳方法的任何幫助都將非常棒!無法使用MKPolygon或polygonWithCoordinates(Swift)

// 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 
} 

回答

1

爲了通過在超時值&coordsMKPolygon(), 陣列必須被聲明爲可變var):

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

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

    // ...  
} 

功能參數是默認恆定,即如同它們 被定義爲let