2

I need this block of code to run in order:

UIApplication.shared.beginIgnoringInteractionEvents()
loadDataTask.resume()
UIApplication.shared.endIgnoringInteractionEvents()

It's being run inside of DispatchQueue.main.async() (every network call is that's why I'm trying to temporarily block user input). I am still learning swift and struggling a little with the GCD concept. Any recommendations would be very much appreciated.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Lucas Earl
  • 395
  • 1
  • 3
  • 13

1 Answers1

2

Just put the endIgnoringInteractionEvents call inside the completion handler of loadDataTask.

UIApplication.shared.beginIgnoringInteractionEvents()
let loadDataTask = session.dataTask(with: request) { data, response, error in
    ...

    DispatchQueue.main.async {
        // do all UI and model updates here

        UIApplication.shared.endIgnoringInteractionEvents()
    }
}
loadDataTask.resume()
Rob
  • 415,655
  • 72
  • 787
  • 1,044