I try to sort tableviewCells by a number inside a label of each cell... for sorting I use following code:
struct sortJobs {
let sDistance = JobTableViewCell.takenLocation
}
var sJobs = [sortJobs]()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.sJobs.sort(by: {$0.sDistance < $1.sDistance}) -> ERROR
self.tableView.reloadData()
}
Where I take the takenLocation from:
static var takenLocation: String?
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let lastLocation = locations.last {
let distance = myLocation.distance(from: jobLocation) / 1000
print(String(format: "The distance to the Job is %.01fkm", distance))
self.distance.text = String(format: "%.01fkm", distance)
JobTableViewCell.takenLocation = self.distance.text
}
Does someone have an idea how I can solve Binary operator '<' cannot be applied to two 'String?' operands ? Or maybe a new way to sort the cells?