Search code examples
iosxcodemkmapviewmapkitmkannotation

Mapkit: mkannotation - How to correctly re-use?


I'll skip some code for the sake of simplicity. I have three kinds of MKannotation(s) (user location, purple pin, and red pin). Each object that I'm representing with purple pins have a unique reuseIdentifier (i.e. its title).

I am aware that it's a good practice to dequeue from the mapView using the reuseIdentifier first before initializing an annotation. My question is regarding the specifics of how it's being reused.

Is it getting reused at the:

a) the type/class of annotation (purple pin, red pin) level or b) the individual annotations level (each purple pins with unique reuseIdentifiers).

Any tip would be appreciated. I want to do this right for the performance reasons.

Thank you!


Solution

  • I think that MKAnnotationView reuse works in a manner similar to the one for UITableViewCells. You need to specify an identifier for a "class" or "type" of annotation views.

    I think that a unique reuse identifier for each view will not provide any performance benefits (probably the opposite). It seems to me that what you're doing will result in caching way too many annotation views and reusing only a few. Keep in mind, that your annotation views are put into the reuse queue as soon as they are moved offscreen (just like table view cells).