Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. class Place {
  2. var placeID: String?
  3. var title: String?
  4. var vicinity: String?
  5. var detailsUrl: String?
  6. var openingHours: OpeningHours?
  7. var position: [Double]
  8.  
  9. var coordinate: CLLocationCoordinate2D {
  10. return CLLocationCoordinate2DMake(position.first ?? 0, position.last ?? 0)
  11. }
  12.  
  13. extension Array {
  14. func removingDuplicates <T: Hashable>(byKey key: (Element) -> T) -> [Element] {
  15. var result = [Element]()
  16. var seen = Set<T>()
  17. for value in self {
  18. if seen.insert(key(value)).inserted {
  19. result.append(value)
  20. }
  21. }
  22. return result
  23. }
  24. }
  25.  
  26.  
  27. let array = list.removingDuplicates(byKey: { "($0.coordinate.latitude)" + "($0.coordinate.longitude)" + ($0.title ?? " ") + ($0.vicinity ?? " ") })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement