Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Place {
- var placeID: String?
- var title: String?
- var vicinity: String?
- var detailsUrl: String?
- var openingHours: OpeningHours?
- var position: [Double]
- var coordinate: CLLocationCoordinate2D {
- return CLLocationCoordinate2DMake(position.first ?? 0, position.last ?? 0)
- }
- extension Array {
- func removingDuplicates <T: Hashable>(byKey key: (Element) -> T) -> [Element] {
- var result = [Element]()
- var seen = Set<T>()
- for value in self {
- if seen.insert(key(value)).inserted {
- result.append(value)
- }
- }
- return result
- }
- }
- let array = list.removingDuplicates(byKey: { "($0.coordinate.latitude)" + "($0.coordinate.longitude)" + ($0.title ?? " ") + ($0.vicinity ?? " ") })
- class Place: Equatable {
- static func == (lhs: Place, rhs: Place) -> Bool {
- return lhs.title == rhs.title && lhs.vicinity == rhs.vicinity &&
- lhs.coordinate.latitude == rhs.coordinate.latitude && lhs.coordinate.longitude == rhs.coordinate.longitude
- }
- //...
- }
- var list = [Place]()
- let placesToDelete = [Place]()
- let result = list.filter { !placesToDelete.contains($0) }
- let placeToDelete = Place()
- let result = list.removeAll { $0 == placeToDelete }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement