7

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?

Grimxn
  • 22,115
  • 10
  • 72
  • 85

1 Answers1

2

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?
Mark Knopper
  • 353
  • 4
  • 6
  • Not sure of which function you speak. I'm speaking about the protocol function `func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer!` – Grimxn Jun 27 '15 at 08:57
  • Oh sorry, my mistake. It's interesting that even the ObjC version of this specifies a non-null return. I'm continuing to look for the answer to this... – Mark Knopper Jun 28 '15 at 01:59
  • Actually I just filed bug #21581742 on this. – Mark Knopper Jun 28 '15 at 02:19
  • 8
    This is a follow-up to Bug ID# 21581742. Engineering has determined that this issue behaves as intended based on the following information: The only overlays which will be passed into this will be overlays that a you've added; There's no such thing as an "unrecognized overlay". Developers must provide a renderer if they add an overlay -- that's how the API works. We consider this issue closed. If you have any questions or concern regarding this issue, please update your report directly (http://bugreport.apple.com). – Mark Knopper Jul 10 '15 at 20:24
  • 1
    Thanks for researching this @MarkKnopper! – Gon Zifroni Oct 23 '15 at 18:16