Hi 在理解 swift 编程中的声明部分时遇到了很多麻烦。
我有一行代码 CLLocationCoordinate2D myCoordinate = myLocation.coordinate;
与我在 Swift 编程中声明的一样,但出现错误
var location1:CLLocation! = locationManager1.location
var coordinate1:CLLocationCoordinate2D = location1.coordinate
fatal error :无法展开 Optional.None
最佳答案
location1
可以是nil
,你必须在访问它的属性之前检查它是否是nil
,例如这个:
let locationManager1: CLLocationManager // your location manager
// ...
if let location1: CLLocation = locationManager1.location {
var coordinate1: CLLocationCoordinate2D = location1.coordinate
// ... proceed with the location and coordintes
} else {
println("no location...")
}
关于ios - swift 将 CLLocation 转换为 CLLocationCoordinate2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24363911/