Hi在理解快速编程中的声明部分时遇到了很多麻烦。
我有一行代码CLLocationCoordinate2D myCoordinate = myLocation.coordinate;
就像我在Swift编程中声明的一样,但是我遇到了错误
var location1:CLLocation! = locationManager1.location
var coordinate1:CLLocationCoordinate2D = location1.coordinate
致命错误:无法解开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 - 快速从CLLocation到CLLocationCoordinate2D,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24363911/