I'm trying to add overlays to an MKMapView, avoiding duplicates by first looking for the overlay in the maps overlays (mapView.overlays: [MKoverlay]) store.
This is what I'm trying currently
func addBoundary(points: [CLLocationCoordinate2D]) -> MKPolygon! {
var x = points
let polygon: MKPolygon = MKPolygon(coordinates: &x, count: points.count)
if overlays.indexOf(polygon as MKOverlay) == nil {
addOverlay(polygon)
return polygon
}
return nil
}
Yet, I'm getting the following error
Cannot convert value of type 'MKOverlay' to expected argument type '@noescape (MKOverlay) throws -> Bool'
I'm guessing it's something simple. I've managed to do checks like this in the past with my own structs, but it doesn't seem to work on pre-defined arrays of common objects.
Can someone please shed some light on my mistakes. I'm guessing it's something to do with MKOverlay not being comparable - if that's the case, I've not certain how best to go about appending that functionality to a pre-defined object...
Many thanks
p.s. This is Swift 2.0
I primarily tried simpler and more logical approach of using
if !overlays.contains(polygon) {
addOverlay(polygon)
}
...yielding an identical error - It seems likely that I'm missing something.