Sending 'MKOverlayView to an incompatible type parameter' id <MKOverlay> '

I get the following warning when adding overlays to my map view:

Sending 'MKOverlayView *const __strong' to parameter of incompatible type 'id<MKOverlay>' 

The code works fine, and the overlays are drawn as they should, but I would like to get rid of the warning. Code calling it:

 for(MKOverlayView *overlay in [mapView overlays]) { [mapView removeOverlay:overlay]; } 

(Obviously, the line inside the for loop is what raises this error) Google does not have a single result for this error. for example, only with MKAnnotationView. The solutions there (for example):

 for(id<MKOverlay> *overlay in [mapView overlays]) { [mapView removeOverlay:overlay]; } 

causes an error.

Any ideas? Thanks!

+4
source share
1 answer

The overlays property returns an array of overlay model objects (objects that comply with the MKOverlay protocol), and not overlay types.

So change the for-loop to:

 for(id<MKOverlay> overlay in [mapView overlays]) { 

Please note that there is no asterisk in the id<MKOverlay> overlay section.

+4
source

All Articles