Skip to content

Commit

Permalink
Merge pull request #9 from Quintschaf/fix-annotation-crash
Browse files Browse the repository at this point in the history
Fix `didDeselect` Crash
  • Loading branch information
JannThomas authored Jun 30, 2023
2 parents a65ffac + 0184889 commit fd8b257
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ extension MapItemPickerController: MKMapViewDelegate {
self.selectedMapItem = selectedMapItem
}

public func mapView(_ mapView: MKMapView, didDeselect annotation: MKAnnotation) {
let optionalAnnotation: MKAnnotation? = annotation
guard let annotation = optionalAnnotation else { return }
// This function is necessary since the annotation handed to `mapView(_ mapView: MKMapView, didDeselect annotation: MKAnnotation)` is sometimes nil. Casting this within the original function works in debug builds, but not in release builds (due to optimization, propably).
private func didDeselect(optional annotation: MKAnnotation?) {
guard let annotation = annotation else { return }

if let cluster = annotation as? MKClusterAnnotation, cluster == selectedMapItemCluster {
selectedMapItemCluster = nil
Expand All @@ -147,6 +147,10 @@ extension MapItemPickerController: MKMapViewDelegate {
}
}

public func mapView(_ mapView: MKMapView, didDeselect annotation: MKAnnotation) {
didDeselect(optional: annotation)
}

// MARK: Compatibility

public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
Expand Down

0 comments on commit fd8b257

Please sign in to comment.