Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 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 ?? " ") })
  28.  
  29. class Place: Equatable {
  30. static func == (lhs: Place, rhs: Place) -> Bool {
  31. return lhs.title == rhs.title && lhs.vicinity == rhs.vicinity &&
  32. lhs.coordinate.latitude == rhs.coordinate.latitude && lhs.coordinate.longitude == rhs.coordinate.longitude
  33. }
  34. //...
  35. }
  36.  
  37. var list = [Place]()
  38.  
  39. let placesToDelete = [Place]()
  40. let result = list.filter { !placesToDelete.contains($0) }
  41.  
  42. let placeToDelete = Place()
  43. let result = list.removeAll { $0 == placeToDelete }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement