title: Swift currentLocation return nil
body: <p>I need to get the current location of the user, but currentLocation return alawas nil. However, CLLocationManager.authorizationStatus is authorizedWhenInUse and on the Map, the pin of my location si correct.</p>
  
  <pre><code>import Foundation
  import CoreLocation
  
  class Location: NSObject, CLLocationManagerDelegate {
      var currentLocation: CLLocation? = nil
      var showUserLocation: Bool?
      var isAuthorised = false {
          didSet {
              if isAuthorised {
                  locationManager.startUpdatingLocation()
                  showUserLocation = true
              } else {
                  locationManager.stopUpdatingLocation()
                  currentLocation = nil
                  showUserLocation = false
              }
          }
      }
  
      private let locationManager = CLLocationManager()
  
      override init() {
          super.init()
  
          locationManager.delegate = self
          locationManager.requestWhenInUseAuthorization()
      }
  
      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
          currentLocation = locations.last
      }
  
      func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
          isAuthorised = (status == .authorizedWhenInUse)
      }
  
      func distance(of position: Position) -&gt; CLLocationDistance {
          let location = CLLocation(latitude: position.lat, longitude: position.lng)
          return currentLocation?.distance(from: location) ?? Double.infinity
      }
  }
  
  extension CLLocationCoordinate2D {
      var position:Position {
          return Position(lat: latitude, lng: longitude)
      }
  }
  </code></pre>
  
  <p>Thank you !</p>
  
  <p><strong>EDIT : I HAVE FIND THE SOLUTION !!!</strong></p>
  
  <p>In my MapViewController, I loaded the annotation before init the Map. So, the function distance was execute BEFORE the function didUpdateLocations.</p>
  
  <p>I am very apologize for the lost time...
  Thank you very much for your help.</p>