swift - 如何延迟方法调用,直到存储了关于更新当前位置的变量值

swift - How to delay method call until variables value is stored regarding updating current location

我想调用一个方法,但它需要尚未存储在变量中的坐标。

到目前为止我有: 1) 获取当前位置 2) 认为我存储它们?

我想做的事情: 1)调用方法 这些变量存起来之后程序就可以运行

class ViewController: UIViewController, CLLocationManagerDelegate  {

let locationManager = CLLocationManager()
var clLatitude : CLLocationDegrees!
var clLongitude: CLLocationDegrees!

override func viewDidLoad() {
    super.viewDidLoad()

    self.locationManager.requestAlwaysAuthorization()
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()


    }



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

    let location:CLLocationCoordinate2D = manager.location!.coordinate

    //Test printing coordinates to screen
    print("locations = \(location.self.clLatitude) \(location.self.clLongitude)")

    //place where I think I store the variables?
    self.clLatitude  = location.latitude
    self.clLongitude = location.longitude

}

func methodToBeCalled(){
     //to be called after variables are stored.
}

我相信我已经解决了关于我的问题的所有问题

我想你只需要调用 locationManager(manager: didUpdateLocations:)

末尾的方法
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let location:CLLocationCoordinate2D = manager.location!.coordinate

    //Test printing coordinates to screen
    print("locations = \(location.self.clLatitude) \(location.self.clLongitude)")

    //place where I think I store the variables?
    self.clLatitude  = location.latitude
    self.clLongitude = location.longitude

    // call method
    methodToBeCalled()
}

func methodToBeCalled(){
     //to be called after variables are stored.
}