我尝试通过每个单元格标签内的数字对tableviewCells进行排序... 对于排序,我使用以下代码:
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()
}
我从以下位置获取takedLocation的地方
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
}
有人知道我该如何解决二进制运算符'<'无法应用于两个'String'吗?操作数?或者也许是一种对细胞进行分类的新方法?