检测位置时,收到错误消息'致命错误:在解包可选值时意外发现nil'

时间:2015-08-07 22:38:49

标签: null location optional clgeocoder

这是我的locationManager函数,有人可以告诉我为什么我收到错误:'致命错误:在解包时意外发现nil可选值'?

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let userLocation: CLLocation = locations[0] as CLLocation

    CLGeocoder().reverseGeocodeLocation(userLocation) { (placemarks, error) -> Void in

    if (error != nil) {

        print(error)

    } else {

        if placemarks!.count > 0 {

            if let pm = placemarks![0] as CLPlacemark! {

            print(pm)

           self.locationButtonLabel.text = "\(pm.subLocality!),\(pm.locality!)"

           }

        }

    }

    }

}

0 个答案:

没有答案