I've created a custom MKPointAnnotation class that simply holds a little extra data.
import UIKit
import MapKit
class MyCustomPointAnnotation: MKPointAnnotation {
var customVariable: Bool!
init(customVariable: Bool) {
self.customVariable = customVariable
}
}
The following code works great:
func addAnnotation() {
let annotation = MyCustomPointAnnotation(customVariable: true)
annotation.coordinate = aCoordinate
annotation.title = "My Title"
map.addAnnotation(annotation)
}
However, I'm not sure how to make that annotation appear as my custom class in a function that gets called when the annotations are being created.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
// Works
print(annotation.title)
//Doesn't work and the variable isn't even available in the code hint
print(annotation.customVariable)
}
The variable annotation that's being pased as an MKAnnotation is maybe stripping my custom class from the annotation? How can I preserve my class as it's passed to other functions?
Thanks!