title: What does 'DispatchQueue.main.async' and 'completed: @escaping () -> ()' mean in this snippet of code?
body: <p>Basically this is a simple project that involves a tableview that is updated according to data that is parsed from JSON from an api. I believe <code>DispatchQueue.main.async</code> and <code>completed: @escaping () -&gt; ()</code> have something to do with updating/reloading the tableview but I'm not sure how it works. Explanation would be appreciated on what these two do.</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      @IBOutlet weak var tableView: UITableView!
  
      var heroes = [HeroStats]()
  
      override func viewDidLoad() {
          super.viewDidLoad()
          fetchData {
              print("Success")
          }
      }
  
      func fetchData(completed: @escaping () -&gt; ()) {
  
          let jsonUrlString = "https://api.opendota.com/api/heroStats"
          guard let url = URL(string: jsonUrlString) else { return }
  
          URLSession.shared.dataTask(with: url) { (data, response, error) in
  
              guard let data = data else { return }
  
              if error == nil {
                  do {
                      let heroes = try JSONDecoder().decode([HeroStats].self, from: data)
                      DispatchQueue.main.async {
                          completed()
                      }
                  } catch let error {
                      print(error)
                  }
              }
          }.resume()        
      }
  }
  </code></pre>