首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在创建CLLocationManager时分配CLLocationManager委托

在创建CLLocationManager时分配CLLocationManager委托
EN

Stack Overflow用户
提问于 2017-11-06 18:36:56
回答 1查看 297关注 0票数 0

如何才能在不出错的情况下完成以下操作?locationManager.delegate = self这行说它不能Cannot assign value of type '(APPLocationManager) -> () -> (APPLocationManager)' to type 'CLLocationManagerDelegate?'

代码语言:javascript
复制
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属性所属类的实例。

EN

回答 1

Stack Overflow用户

发布于 2017-11-06 18:50:42

在启动任何服务之前,应将委托对象分配给CLLocationManager对象的delegate属性。因为-

代码语言:javascript
复制
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
    }()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47134911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档