Hi had lot of trouble in understanding the declaration part in swift programming. I have line of code CLLocationCoordinate2D myCoordinate = myLocation.coordinate;
As same as I declared in Swift programming but I'm getting error
var location1:CLLocation! = locationManager1.location
var coordinate1:CLLocationCoordinate2D = location1.coordinate
fatal error: Can't unwrap Optional.None
the location1
can be nil
, and you have to check whether or not it is nil
before you access to its proprties, like eg this:
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...")
}
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.