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

MGLPointAnnotation Hashable conformance #6677

Closed
ollie-eman opened this issue Oct 12, 2016 · 4 comments
Closed

MGLPointAnnotation Hashable conformance #6677

ollie-eman opened this issue Oct 12, 2016 · 4 comments
Labels
iOS Mapbox Maps SDK for iOS

Comments

@ollie-eman
Copy link

Platform: iOS
Mapbox SDK version: 3.3.4

Steps to trigger behavior

I've created a subclass of MGLPointAnnotation named MyCustomAnnotation

class MyCustomAnnototation: MGLPointAnnotation { }

and defined a Set to store the annotations, to ensure I don't add any duplicates.

var annotations = Set<MyCustomAnnotation>()

Next i've created two annotations:

let coordinate = CLLocationCoordinate2D(latitude: 51.50, longitude: -0.12)
let annotationOne = MyCustomAnnotation(location: coordinate)
let annotationTwo = MyCustomAnnotation(location: coordinate)

To insert the annotations:

var insertionResult = annotations.insert(annotationOne)
if insertionResult.inserted {
    print("Annotation one inserted")
}

insertionResult = annotations.insert(annotationTwo)
if insertionResult.inserted {
    print("Annotation two inserted")
}

Expected behavior

The first annotation (annotationOne) should be inserted successfully into the Set. The second annotation (annotationTwo) should not be inserted as an annotation with the same coordinates already exists.

Actual behavior

Both annotations are added to the Set

@boundsj
Copy link
Contributor

boundsj commented Oct 13, 2016

Thanks @ollie-eman. I think this will be fixed when #6559 lands. Although, note that in that implementation the hash would not be just a function of coordinate latitude and longitude as you've noted above.

@ollie-eman
Copy link
Author

Great thanks @boundsj. Taking into consideration the hash implementation, do you think it will fix the issue i'm having and enable me to store the annotations in a Set? Also, do you know when it might be available via Cocoapods?

@boundsj
Copy link
Contributor

boundsj commented Oct 14, 2016

do you think it will fix the issue i'm having and enable me to store the annotations in a Set

From what I can tell, yes. Assuming MyCustomAnnotation is the "same" in the context of MGLPointAnnotation's hash or your subclass's override.

do you know when it might be available via Cocoapods

#6559 fixes #6200 which is currently planned for our next release.

@jfirebaugh jfirebaugh added the iOS Mapbox Maps SDK for iOS label Oct 17, 2016
@1ec5
Copy link
Contributor

1ec5 commented Jan 13, 2017

Fixed in #6559.

@1ec5 1ec5 closed this as completed Jan 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

4 participants