How else can I reload a table view without getting this error?
You go to the main thread to call reloadData
, for example:
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) in self.jsonResult = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSMutableArray dispatch_async(dispatch_get_main_queue()) { self.tableView.reloadData() } }
Always do this when you touch an interface from code that was called in the background thread. You should never ever touch an interface other than the main thread.
source share