Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

signature for callOutViewFor:annotation should have MGLCalloutView return type #8420

Closed

Description

@idrougge

Platform: Swift
Mapbox SDK version: 3.4.1

func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> UIView? as a signature is misleading since the function expects the return UIView to conform to MGLCalloutView and will cause a crash because of sending incorrect selectors. The return type should be changed to MGLCalloutView in order to reflect this.

Activity

  1. added
    annotations
    iOS
    on Mar 15, 2017
  2. added this to the ios-v3.5.1 milestone on Mar 17, 2017
  3. changed the title [-][ios][macos] signature for callOutViewFor:annotation should have MGLCalloutView return type[/-] [+]signature for callOutViewFor:annotation should have MGLCalloutView return type[/+] on Mar 17, 2017
  4. 1ec5 commented on Mar 17, 2017

    @1ec5
    Contributor

    Retitling, because macOS is unaffected: -[MGLMapViewDelegate mapView:calloutViewControllerForAnnotation:] returns an NSViewController, and the return value is always treated as a plain NSViewController.

  5. added
    Swift
    on Mar 27, 2017
  6. self-assigned this
    on Mar 27, 2017
  7. boundsj commented on Mar 30, 2017

    @boundsj
    Contributor

    This was fixed by #8541 that landed in the release-ios-v3.5.0-android-v5.0.0 branch and will be in the ios v3.5.1 patch release

  8. boundsj commented on Mar 30, 2017

    @boundsj
    Contributor

    Reopening.

    Unfortunately, I missed that this change causes a warning in MGLMapView:

    calloutView = [self.delegate mapView:self calloutViewForAnnotation:annotation];

    triggers:

    /mapbox-gl-native/platform/ios/src/MGLMapView.mm:3764:27: Incompatible pointer types assigning to 'UIView<MGLCalloutView> *' from 'id<MGLCalloutView> _Nullable'
    

    The naming of MGLCalloutView protocol and its documentation make the correct choice for what base type to return fairly obvious. However, I think we should guard against using objects that are not a kind of UIView and, if they are views, cast them as such to silence the warning.

    cc @1ec5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SwiftannotationsiOS

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions