在
Swift 1.2中我有这个:
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已将mapView:rendererForOverlay的定义更改为现在返回MKOverlayRenderer而不是MKOverlayRenderer!,现在不允许我返回nil(不出所料)因为MKOverlayRenderer不是NilLiteralConvertible.但是,文档(在Xcode 7中)仍然说:
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.
如果通过我不认识的叠加层,我应该返回什么?
解决方法
根据最新的MKMapView.h,新的函数声明现在是:
// Current renderer for overlay; returns nil if the overlay is not shown. @available(iOS 7.0,*) func rendererForOverlay(overlay: MKOverlay) -> MKOverlayRenderer?