iosswiftuitableviewsvprogresshud

SVProgressHUD not displaying until UITableView is displayed


I am trying to use the SVProgressHUD to indicate that the app is busy.

My code is now:

        SVProgressHUD.show()
        DispatchQueue.global(qos: .background).async {
            parser.parse()
            print("start reloading")
            self.protocolTableView.reloadData()

            print("end reloading")
            SVProgressHUD.dismiss()
        }

I get this warning:

UITableView.reloadData() must be used from main thread only

And it takes quite a while before the tableView is displayed after the parsing has been done.

How can I update the tableView after reading in the parsing from the main thread?

Thanks, Bart


Solution

  • XMLParser.parse can block the UI. Try doing that on a background thread:

    DispatchQueue.global(qos: .background).async {
        parser.parse()
    }