What do you mean by setting a tag to each annotation?
Unfortunately, you cannot add the tag directly.
What I did was to use the title to add this information.
Either with an explicit number (at the beginning or at the end). That's what you do if you give title as One, Two…
I used a trick to add sequence of invisible characters (space and optionSpace)
You could modify findPlace for this:
func findPlace(_ miejsca: [Place]) {
for (i, place) in places.enumerated() {
let annotations = MKPointAnnotation()
annotations.title = String(i) + "-" + place.name // initial chars before "-" give the "tag"
annotations.subtitle = place.description
annotations.coordinate = CLLocationCoordinate2D(latitude:
place.lattitude, longitude: place.longtitude)
mapView.addAnnotation(annotations)
}
}
Then, in
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
You retrieve this Int at the beginning to use in the switch case.
You do not show the different didClickDetailDisclosure.
You could have:
// for VC1
@objc func didClickDetailDisclosure1(button: UIButton) {
guard let vc = storyboard?.instantiateViewController(withIdentifier: "kopuly_vc1") as? KopulyController else { return }
present(vc, animated: true)
}
// for VC2
@objc func didClickDetailDisclosure2(button: UIButton) {
guard let vc = storyboard?.instantiateViewController(withIdentifier: "kopuly_vc2") as? KopulyController else { return }
present(vc, animated: true)
}
Hope that's clear.