title: URLSession.shared.dataTask freezes the UI
body: <p>I am making a <code>Swift</code> app for iOS and I have an issue on a request I make.</p>
  
  <p>This request is made every 3 to 5 seconds and the body is a 5k lines JSON (~130k characters in total) that refreshes a <code>UITableView</code>. The issue is that every time <code>.dataTask</code> is used on this specific request, the app freezes then runs normally after the request has been made.</p>
  
  <p>By "freezes" I mean that I've detected it when I scroll my long UITableView. Even a small scroll list freezes.</p>
  
  <p>I first suspected the update of the <code>UITableView</code>, but I added a small 'hack' that disables the update of the <code>UITableView</code> when scrolling, like this:</p>
  
  <pre><code>    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
          print("started scrolling")
          self.currentlyScrolling = true
      }
  
      func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
          print("stopped scrolling")
          self.currentlyScrolling = false
      }
  </code></pre>
  
  <p>It doesn't work.</p>
  
  <p>My question is then: I think that dataTask is NOT run in the main thread. But I am not sure. How can I check it? Also, how can I be sure that dataTask is async ?</p>
  
  <p>Here's what the <code>dataTask</code> code looks like:</p>
  
  <pre><code>let task = URLSession.shared.dataTask(with: req) { data, response, err in
          guard let data = data, err == nil else {
              // error
              return
          }
  
          if let resp = try? JSONSerialization.jsonObject(with: data) {
              // success
          }
      }
  
      task.resume()
  </code></pre>
  
  <p>Little note however, it ONLY freezes BEFORE the JSONSerialization, not after, so I guess it is not what it is causing the freeze.</p>