dequeueReusableAnnotationView(withIdentifier:for:)
Returns a reusable annotation view using the specified identifier with a specified existing annotation view, if possible.
Declaration
func dequeueReusableAnnotationView(withIdentifier identifier: String, for annotation: any MKAnnotation) -> MKAnnotationViewParameters
- identifier:
A string identifying the annotation view to create.
- annotation:
The annotation the map is displaying. This method automatically assigns this annotation object to the returned annotation view.
Return Value
An annotation view with the specified identifier.
Discussion
For performance reasons, be sure to reuse MKAnnotationView objects in your map views. As annotation views move offscreen, the map view moves them to an internally managed reuse queue. As new annotations move onscreen, and the map view prompts your code to provide a corresponding annotation view, use this method to dequeue an existing view. Dequeueing saves time and memory during performance-critical operations, such as scrolling.
If the map view can dequeue an existing view, this method tries to create one from the specified identifier. Before this can happen, you need to register an annotation view class using the register(_:forAnnotationViewWithReuseIdentifier:) method. If there’s no registered class with the appropriate identifier, this method throws an exception.