Instance Method

dequeueReusableAnnotationView(withIdentifier:)

Returns a reusable annotation view located by its identifier.

Declaration

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

Parameters

identifier

A string identifying the annotation view to be reused. 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, you should generally 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 your code is prompted to provide a corresponding annotation view, you should always attempt to dequeue an existing view before creating a new one. Dequeueing saves time and memory during performance-critical operations such as scrolling.

See Also

Annotating the Map

var annotations: [MKAnnotation]

The complete list of annotations associated with the receiver.

func addAnnotation(MKAnnotation)

Adds the specified annotation to the map view.

func addAnnotations([MKAnnotation])

Adds an array of annotation objects to the map view.

func removeAnnotation(MKAnnotation)

Removes the specified annotation object from the map view.

func removeAnnotations([MKAnnotation])

Removes an array of annotation objects from the map view.

func view(for: MKAnnotation)

Returns the annotation view associated with the specified annotation object, if any.

func annotations(in: MKMapRect)

Returns the annotation objects located in the specified map rectangle.

var annotationVisibleRect: CGRect

The visible rectangle where annotation views are currently being displayed.