对CLLocationDegrees对象进行排序(Sorting Array of CLLocationDegrees Objects)

编程入门 行业动态 更新时间:2024-10-25 15:36:55
对CLLocationDegrees对象进行排序(Sorting Array of CLLocationDegrees Objects)

我正在尝试排序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.

更多推荐

本文发布于:2023-08-07 16:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465522.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   CLLocationDegrees   Sorting   Objects   Array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!