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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With