0

I'm using this function to change the location of the map marker based on user selection:

let annotation = MKPointAnnotation()   //global reused annotation object
func setPin(mapView: MKMapView, longitude: Double, latitude: Double, title: String) {        
    annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
    annotation.title = title
    mapView.addAnnotation(annotation)
}

The coordinates and title changes repeatedly, so I'm a little concerned if this is the correct approach. The MKPointAnnotation object is instantiated only once, as a global, and only its contents are updated when the setPin() function is called. So far, it's been working without issue, besides the glitch with the simulator not refreshing/rendering the title sometimes.

Would doing this cause any leaks? Am I missing any steps to free the obejct or remove it from the map before reusing it, perhaps?

TIA.

iSofia
  • 1,412
  • 2
  • 19
  • 36
  • You should not reuse annotation object to avoid bug which the simulator not refreshing/rendering the title sometimes. – Kosuke Ogawa May 16 '18 at 01:01
  • @KosukeOgawa: Thank you for your answer. Yes, my MacBook uses the Intel3000 HD GPU which is the one causing the render/refresh issues. However, if not for that, is it safe to reuse the same MKPointAnnotation object? It's easier because it maintains a reference to the object when removing the previous location before updating it to the new location. – iSofia May 16 '18 at 02:51

0 Answers0