mapkit-ios-demo
mapkit-ios-demo copied to clipboard
Could not cast value of type 'YMKPlacemarkMapObject' (0x11686f1d8) to 'YMKPlacemarkMapObject' (0x11d783958).
i have cluster collection and for placeMarks in this collection i added YMKMapObjectTapListener.
this is my onMapObjectTap method
and when i click on a placemark, i got crash with this error "Could not cast value of type 'YMKPlacemarkMapObject' (0x111c031d8) to 'YMKPlacemarkMapObject' (0x118b17960)."
What am i doing wrong?
try this
guard let placemarkObj = mapObject as? YMKPlacemarkMapObject else { return false }
return true
Because you are using clusterized collection you should implement two tap listeners: one for object taps (the one you have implemented), and the other one for cluster taps, e.g.:
func onClusterTap(with cluster: YMKCluster) -> Bool {
// do smth with cluster here (zoom in for example)
return true
}
func onMapObjectTap(with mapObject: YMKMapObject, point _: YMKPoint) -> Bool {
guard let placemarkObj = mapObject as? YMKPlacemarkMapObject else { return false }
// do smth with object here
return true
}