Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2 MKMapViewDelegate rendererForOverlay optionality

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?

like image 209
Grimxn Avatar asked Jun 10 '15 08:06

Grimxn


Video Answer


1 Answers

According to the most recent MKMapView.h, the new function declaration is now:

// Current renderer for overlay; returns nil if the overlay is not shown.
@available(iOS 7.0, *)
func rendererForOverlay(overlay: MKOverlay) -> MKOverlayRenderer?
like image 130
Mark Knopper Avatar answered Oct 20 '22 21:10

Mark Knopper