Contents

dequeueReusableAnnotationView(withIdentifier:)

Returns a reusable annotation view using its identifier.

Declaration

func dequeueReusableAnnotationView(withIdentifier identifier: String) -> MKAnnotationView?

Parameters

  • identifier:

    A string identifying the annotation view for the map view to reuse. This string is the same one you specify when initializing the annotation view using the Init(annotation:reuseidentifier:) method.

Return Value

An annotation view with the specified identifier, or nil if no such object exists in the reuse queue.

Discussion

For performance reasons, it’s best practice 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, attempt to dequeue an existing view before creating a new one. Dequeueing saves time and memory during performance-critical operations like scrolling.

See Also

Creating annotation views