title: Swift 4 CLLocationManager question: Can I use the location, which is got from CLLocationManager, in ViewDidLoad function?
body: <p>Followed the instructions online, I was able to get my current location using CLLocationManager. And the code structure is as below:</p>
  
  <pre><code>var myCurCoordinate:String!
  
  override func viewDidLoad() {
          super.viewDidLoad()
          getLocation()
         print(myCurCoordinate) // HERE I GOT "nil". In my original code, I am not really printing it. Instead, I have another function here that needs to use myCurCoordinate
  }
  
  func getLocation() {
          locationManager = CLLocationManager()
          locationManager.delegate = self
          locationManager.desiredAccuracy = kCLLocationAccuracyBest
          locationManager.requestAlwaysAuthorization()
  
          if CLLocationManager.locationServicesEnabled() {
              locationManager.startUpdatingLocation()
          }
      }
  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      let loc:CLLocation = locations[0] as CLLocation
      myCurCoordinate="\(loc.coordinate.latitude),\(loc.coordinate.longitude)"
      print(myCurCoordinate) // HERE print 3 times because of its async
  }
  </code></pre>
  
  <p>Can anyone help figure out how can I obtain the location information and be able to print it in the viewDidLoad() ?</p>
  
  <p>Thank you!</p>