我从核心数据实体填充了UITableView
以显示位置名称以及这些位置的纬度和经度。在Swift中按距离对UItableview进行排序
我设法计算从用户到存储位置的距离并显示距离。
var templat = NSString(string: location.lat)
var templong = NSString(string: location.long)
var distinationCoords: CLLocation = CLLocation(latitude: templat.doubleValue, longitude: templong.doubleValue)
var distance: CLLocationDistance = distinationCoords.distanceFromLocation(mypoi.sharedlocation)
classdistance = distance/1000
cell.customCellSubTitle?.text = "\(distance)"
现在,我该如何根据距离当前位置的距离排序位置。
我可以很容易地按名称排序或存储在核心数据的任何值,但距离需要从检索到的数据计算,当我做计算这将是
请帮助,如果后期这样排序细胞你可以
非常感谢你提前
的延伸?如果是,则存储与coredata的距离并使用NSSortDescriptor对它们进行排序。如果您想要更多帮助,请告诉我 –
您无法在NSSortDescriptor中计算距离,因为您必须使用CLLocation&CLLocationDistance。 –
你的核心数据实体有哪些属性? – ABakerSmith