MKPolygon using Swift (missing argument for the parameter "internalPolygons" in the call)

Supporters of Devs, I'm trying to implement a polygon overlay on a view map as follows:

private func drawOverlayForObject(object: MyStruct) {
    if let coordinates: [CLLocationCoordinate2D] = object.geometry?.coordinates {
        let polygon = MKPolygon(coordinates: coordinates, count: coordinates.count)
        self.mapView.addOverlay(polygon)
    }
}

The following error is presented:

Missing argument for 'innerPolygons' parameter in call

According to the documentation: Apple Docu:

Variable pointers

When a function is declared as taking an UnsafeMutablePointer argument, it can accept any of the following:

  • nil, which is passed as a null pointer
  • UnsafeMutablePointer value
  • An in-out expression whose operand is the stored value of type l, which is passed as the address lvalue
  • An in-out [Type] value that is passed as a pointer to the beginning of the array and is extended for the entire duration of the call

, , [CLLocationCoordinate2D]. - ?

Ronny

+4
2

, , - Swift , , . interiorPolygons, :

'innerPolygons'

; . , , , , :

in-out [Type], ,

, in-out. coordinates &, :

MKPolygon(coordinates: &coordinates, count: coordinates.count)

. :

in-out. , .

, coordinates var:

if var coordinates: [CLLocationCoordinate2D] = object.geometry?.coordinates

:

private func drawOverlayForObject(object: MyStruct) {
    if var coordinates: [CLLocationCoordinate2D] = object.geometry?.coordinates {
        let polygon = MKPolygon(coordinates: &coordinates, count: coordinates.count)
        self.mapView.addOverlay(polygon)
    }
}
+9

:

func setPolylineFromPoints(locations:[CLLocation]){
    if locations.count == 0 {
        return;
    }
// while we create the route points, we will also be calculating the bounding box of our route
// so we can easily zoom in on it.
    var pt : UnsafeMutablePointer<MKMapPoint>? // Optional
    pt = UnsafeMutablePointer.alloc(locations.count)
    for idx in 0..<locations.count-1 {
       let location = locations[idx]
       let point = MKMapPointForCoordinate(location.coordinate);
       pt![idx] = point;
    }
    self.polyline = MKPolyline(points:pt!, count:locations.count-1)
// clear the memory allocated earlier for the points
    pt?.destroy()
    pt?.dealloc(locations.count)
}  
0

All Articles