title: wait for my for loop to finish before reloading data on tableview? Swift
body: <p>I haven't used swift in a while but wanted to mess around with the new PHPicker and try my hands on it
  I have a simple app that takes photos from the user's library and present them in a tableview
  I use a simple bar button to prompt the user for images to use but when I add the images the first time the array comes up empty but the second time it uses the images from the first go.
  I'm doing something wrong but I can't tell what it is please help!</p>
  <pre><code>import Photos
  import PhotosUI
  import UIKit
  
  class PhotosListScreen: UIViewController {
      
      @IBOutlet weak var tableView: UITableView!
      @IBOutlet weak var barButton: UIBarButtonItem!
      var tempPhotos = [UIImage]()
      override func viewDidLoad() {
          super.viewDidLoad()
          tableView.delegate = self
          tableView.dataSource = self
      }
      
  }
  
  extension PhotosListScreen: PHPickerViewControllerDelegate,   UITableViewDataSource, UITableViewDelegate {
      func presentPhpicker() {
          var config = PHPickerConfiguration()
          config.selectionLimit = 0
          config.filter = PHPickerFilter.images
          
          let pickerViewController = PHPickerViewController(configuration: config)
          pickerViewController.delegate = self
          self.present(pickerViewController, animated: true, completion: nil)
          
              
      }
      
      func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult])  {
          picker.dismiss(animated: true, completion: nil)
          for result in results {
              result.itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { (object, error) in
                  if let image = object as? UIImage {
                      DispatchQueue.main.async {
                          self.tempPhotos.append(image)
                      }
                  }
              })
          }
          print(&quot;Selected image: \(tempPhotos)&quot;) // Empty the first time
          tableView.reloadData()
      }
      
      @IBAction func addPhotos(_ sender: Any) {
          DispatchQueue.main.async {
              self.presentPhpicker()
          }
      }
      
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return tempPhotos.count
      }
      
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let photo = tempPhotos[indexPath.row]
          let cell = tableView.dequeueReusableCell(withIdentifier: &quot;PhotoCell&quot;) as! PhotoCell
          cell.setPhoto(photo: photo)
          return cell
      }
  }
  </code></pre>