如何才能在不出错的情况下完成以下操作?locationManager.delegate = self这行说它不能Cannot assign value of type '(APPLocationManager) -> () -> (APPLocationManager)' to type 'CLLocationManagerDelegate?'
let locationManager: CLLocationManager = {
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.activityType = CLActivityType.other
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = true
locationManager.distanceFilter = APPLocationManagerDistanceFilter
return locationManager
}()我希望委托是locationManager属性所属类的实例。
发布于 2017-11-06 18:50:42
在启动任何服务之前,应将委托对象分配给CLLocationManager对象的delegate属性。因为-
class ViewController: UIViewController, CLLocationManagerDelegate{
lazy var locationManager: CLLocationManager = {
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.activityType = CLActivityType.other
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = true
locationManager.distanceFilter = APPLocationManagerDistanceFilter
return locationManager
}()https://stackoverflow.com/questions/47134911
复制相似问题