2017-11-06 1 views
0

エラーを起こさずに次の操作を行うにはどうすればよいですか?ラインlocationManager.delegate = selfは、私は、デリゲートがlocationManager財産がその一部となっているクラスのインスタンスになりたいことがCannot assign value of type '(APPLocationManager) ->() -> (APPLocationManager)' to type 'CLLocationManagerDelegate?'CLLocationManagerを作成するときにCLLocationManagerデリゲートを割り当てる

let locationManager: CLLocationManager = { 
    let locationManager = CLLocationManager() 

    locationManager.delegate = self 
    locationManager.activityType = CLActivityType.other 
    locationManager.allowsBackgroundLocationUpdates = true 
    locationManager.pausesLocationUpdatesAutomatically = true 
    locationManager.distanceFilter = APPLocationManagerDistanceFilter 

    return locationManager 
}() 

できないと言います。

+0

最初の行に。 letをlazy varに変更する – Honey

答えて

1

サービスを開始する前に、委任オブジェクトをCLLocationManagerオブジェクトの委任プロパティに割り当てる必要があります。 as -

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 
    }() 
関連する問題