In Swift 1.2 I have this:
class UVC: NSViewController, MKMapViewDelegate {
// ...
// **************************************
// MARK: MapView Delegate
// **************************************
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer! {
if overlay is OSGBTiles {
return OSGBTilesRenderer(tileOverlay: overlay as! OSGBTiles)
} else if overlay is ESRI {
return ESRIRenderer(shapeFileOverlay: overlay as! ESRI)
} else if overlay is MKTileOverlay {
return MKTileOverlayRenderer(overlay: overlay)
} else {
print("Unknown overlay")
}
return nil
}
}
Swift 2 has changed the definition of mapView:rendererForOverlay
to now return MKOverlayRenderer
rather than MKOverlayRenderer!
, and will not now allow me to return nil
(unsurprisingly) as MKOverlayRenderer
is not NilLiteralConvertible
. However, the documentation (in Xcode 7) still says:
Return Value
The renderer to use when presenting the specified overlay on the map. If you return nil, no content is drawn for the specified overlay object.
What am I supposed to return if passed an overlay that I don't recognise?
According to the most recent MKMapView.h, the new function declaration is now: