我正在尝试排序2个CLLocationDegrees对象数组,以便我可以确定使用Swift使地图居中的最小和最大纬度和经度。
var latitudes = [CLLocationDegrees]() var longditudes = [CLLocationDegrees]() self.latitudes.append(mylocation.coordinate.latitude) self.longditudes.append(mylocation.coordinate.longitude) latitudes = latitudes.sort({ $0 < $1 }) longditudes = longditudes.sort({ $0 < $1 })当我去排序数组时,我得到错误:“()不能转换为类型[(CLLocationDegrees)]”
我不确定我是否理解这一点,CLLocationDegree对象存储为Double值,为什么我不能以这种方式对它们进行排序?
I'm trying to sort 2 arrays of CLLocationDegrees Objects such that I can determine a minimum and maximum latitude and longitude to centre a map with Swift.
var latitudes = [CLLocationDegrees]() var longditudes = [CLLocationDegrees]() self.latitudes.append(mylocation.coordinate.latitude) self.longditudes.append(mylocation.coordinate.longitude) latitudes = latitudes.sort({ $0 < $1 }) longditudes = longditudes.sort({ $0 < $1 })When I go to sort the arrays I get the error: "() is not convertible to type [(CLLocationDegrees)]"
I'm not sure that I understand this, CLLocationDegree objects are stored as Double values, why can I not sort them in this manner?
最满意答案
把它放进游乐场,看看你想要做的事情的两种方式
import UIKit import CoreLocation var latitudes : [CLLocationDegrees] = [] var longditudes :[CLLocationDegrees] = [] latitudes.append(100.0) // Just using a Double as an example longditudes.append(120.0) latitudes.sort() { $0 < $1 } longditudes.sort({ $0 < $1 })sort执行排序,因此您无法将其分配给自身。
Put this into a playground to see two ways of doing what you are trying to do
import UIKit import CoreLocation var latitudes : [CLLocationDegrees] = [] var longditudes :[CLLocationDegrees] = [] latitudes.append(100.0) // Just using a Double as an example longditudes.append(120.0) latitudes.sort() { $0 < $1 } longditudes.sort({ $0 < $1 })sort performs the sort in place so you can't assign it to itself.
更多推荐
发布评论