La bla bla
La bla bla

Reputation: 8708

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

I'm getting the following warning when adding overlays to my map view:

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

The code works great, and the overlays are drawn as they should, but I would love to get rid of the warning. The code that's causing it:

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

(Obviously, the line inside the for loop is what's raising this error) Google doesn't have a single result for that error. only similar with MKAnnotationView for example. The solutions there (for example):

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

raises an error.

Any ideas? Thanks!

Upvotes: 4

Views: 896

Answers (1)

user467105
user467105

Reputation:

The overlays property returns an array of the overlay model objects (the objects that conform to the MKOverlay protocol) and not the overlay views.

So change the for-loop to:

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

Note there is no asterisk in the id<MKOverlay> overlay part.

Upvotes: 4

Related Questions