1

I have this button, that should show/hide certain annotation pins on my map. I have this function down below, but when you press it to remove the pins, it removes all pins. It should only remove the pins that are inside the addAttractionPinsBilka? What can I do to make this happen?

Here is my code:

@IBAction func bilkaAction(sender: AnyObject) {
    if !annotationBilkaIsVisible {
        addAttractionPinsBilka()
        annotationBilkaIsVisible = true

    }else {
        map.removeAnnotations(map.annotations)
        annotationBilkaIsVisible = false
    }
}

Hope you can help me :-)

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Mus Harlem
  • 185
  • 4
  • 19
  • The following code removes all annotations: `map.removeAnnotations(map.annotations)` What kind of annotations are added in `addAttractionPinsBilka()`? You have to remove only annotations of that kind. – Andreas Bauer Apr 15 '16 at 08:08
  • @AndreasBauer a lot of these are inside the addAttractionPinsBilka(): `let bilka1 = Artwork(title: "Bilka, Hillerød", locationName: "Tryk for rute", discipline: "Butik", coordinate: CLLocationCoordinate2D(latitude: 55.931326, longitude: 12.284186))` – Mus Harlem Apr 15 '16 at 08:18
  • Ok the annotations are of type `Artwork`. See my answer below. Hope that helps. – Andreas Bauer Apr 15 '16 at 08:28

1 Answers1

0

Let's say the annotations you add in addAttractionPinsBilka() are of type Artwork

The following code removes all annotations of that type

for annotation in map.annotations where annotation is Artwork {
    map.removeAnnotation(annotation)
}
Andreas Bauer
  • 171
  • 1
  • 6