...
var places: Results<Place>?
init() {
super.init(nibName: "PlacesViewController", bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
...
places = realm.objects(Place)
}
func sortPlacesByDistanceFromUser(userLocation: CLLocation) -> [Place] {
let realm = try! Realm()
let placesSortedByDistance = realm.objects(Place).sort { (a, b) -> Bool in
return a.location!.distanceFromLocation(userLocation) < b.location!.distanceFromLocation(userLocation)
}
return venuesSortedByDistance
}
This function return an `Array`, because (as far as I know) `Results<T>` cannot be sorted like this. Is there a way to convert an `Array` back into `Results`? Am I missing something obvious?
Thank you.