title: Swift get location THEN load table
body: <p>So I want to ask a user for their location when they open the app for the first time and THEN load the table. Here's my present code:</p>
  
  <pre><code>class LayoutController: UICollectionViewController, UICollectionViewDataSource,
  UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, 
  APIControllerProtocol, CLLocationManagerDelegate {
  
  
      @IBOutlet weak var chainTable: UICollectionView!
      @IBOutlet weak var navLogo: UIButton!
      let locationManager : CLLocationManager = CLLocationManager()
  
      var lat: String = "lat!"
      var long: String = "long!"
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          UIApplication.sharedApplication().statusBarStyle = .LightContent
          navLogo.userInteractionEnabled = false
  
          self.locationManager.delegate = self
          self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
          self.locationManager.requestWhenInUseAuthorization()
          self.locationManager.startUpdatingLocation()
          if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedWhenInUse || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedAlways){
              var currentLocation = locationManager.location
              var longitude = currentLocation.coordinate.longitude
              var latitude = currentLocation.coordinate.latitude
  
              long = String(stringInterpolationSegment: longitude)
              lat = String(stringInterpolationSegment: latitude)
          }
          // Do any additional setup after loading the view.            
          loadTable(lat, longitude, long)
      }
  
      func loadTable(latitude: String, longitude: String){
          api = APIController(delegate: self)
          UIApplication.sharedApplication().networkActivityIndicatorVisible = true
          api!.getPosts(latitude, longitude: longitude)
      }
  }
  </code></pre>
  
  <p>The data doesn't properly load on the first download and after location is enabled. I does work when you restart the app however. How can I make the table check if the location is given before loading?  Thanks.</p>
  
  <p>(I have tried it with the loadTable function inside the <code>if CLLocationManager.authorizationstatus()...</code> block to no avail either.)</p>