Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nil is incompatible with return type 'MKOverlayRenderer'

I am getting this error

"Nil is incompatible with return type 'MKOverlayRenderer'".

Here is my code:

func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
    if overlay is MKCircle {
      let circleRenderer = MKCircleRenderer(overlay: overlay)
      circleRenderer.lineWidth = 1.0
      circleRenderer.strokeColor = UIColor.purpleColor()
      circleRenderer.fillColor = UIColor.purpleColor().colorWithAlphaComponent(0.4)
      return circleRenderer
    }
      return nil
  }

why is it occurring?

like image 232
Ganesh Kumar Avatar asked Oct 13 '15 12:10

Ganesh Kumar


2 Answers

return MKPolylineRenderer() instead of returning nil.

like image 74
shivamkaushik Avatar answered Nov 14 '22 20:11

shivamkaushik


This seems to be answered here:

Swift 2 MKMapViewDelegate rendererForOverlay optionality

You are just not allowed to return nil. Your overlay must have a renderer. Replace "return nil" with an assertion.

like image 28
gnasher729 Avatar answered Nov 14 '22 21:11

gnasher729