У меня проблемы. Я создал собственный класс для моей MKPointAnnotation, который содержит «идентификатор».
Теперь я хочу сравнить идентификатор, и если оба идентификатора совпадают, я хочу удалить аннотацию.
На данный момент у меня есть этот код, который проверяет, являются ли annotation.title и user.username одинаковыми, но я хочу изменить его с помощью: annotation.identifier и user.id.
for annotation in self.mapView.annotations {
if let title = annotation.title, title == user.username {
self.mapView.removeAnnotation(annotation)
}
}
Что касается пользовательского класса аннотации:
class MyAnnotation: MKPointAnnotation {
var identifier: String!
}
А для создания аннотации:
let annotation = MyAnnotation()
annotation.title = user.username
annotation.subtitle = user.job
annotation.identifier = user.email
annotation.coordinate = CLLocationCoordinate2D(latitude: (Double(user.latitude ?? "0"))!, longitude: (Double(user.longitude ?? "0"))!)
self.mapView.addAnnotation(annotation)