How do Views relate/loosely couple to Annotations? Annotationsarray I got, Views I need

49 views Asked by At

SryImNew: (lets say I want to Display gliphXYZ if title == "home")

"Annotation views are loosely coupled to a corresponding annotation object" https://developer.apple.com/documentation/mapkit/mkannotationview

How to couple them loosely, and where? Or do I already have multiple MKAnnotationView automatically, if so how to address them & their properties?

My Case

I have running: An app that shows multiple pins for locations on a map by

rawArrayWithFormat=[[namestring,lat,long][namestring,lat...]]

class Place: NSObject, MKAnnotation {
      var title: String?
      var subtitle: String?
      var latitude: Double
      var longitude:Double

      var coordinate: CLLocationCoordinate2D {
      return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
      }

      init(latitude: Double, longitude: Double) {
      self.latitude = latitude
      self.longitude = longitude
} 

Function that returns Array of [Place] by iterating through rawArray

func getMapAnnotations() -> [Place] {
var annotations:Array = [Place]()    

for item in rawArray {

    let lat = (item[1] as AnyObject) as! Double
    let long = (item[2] as AnyObject) as! Double
    let annotation = Place(latitude: lat, longitude: long)


    annotation.title = (item[0] as AnyObject) as? String
    annotations.append(annotation)
} 
return annotations

And then in ViewController

@IBOutlet weak var mapView: MKMapView!
...

finally I call in override func viewDidLoad{

         mapView.addAnnotations(getMapAnnotations())
0

There are 0 answers