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?
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.
Just try to read what compiler says. " ()
is not convertible to the type [(CLLocationDegrees)]
. The ()
means Void
. Thats right. Void
is just typealiased empty tuple which is ()
. So the compiler says you are assigning Void
to CLLocationDegrees
array. That means latitudes.sort({ $0 < $1 })
returns Void
.
From here you can continue to read @Abizern's answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.