Swift UITableView reloadData in a closure Swift UITableView reloadData in a closure ios ios

Swift UITableView reloadData in a closure


UIKit isn't thread safe. The UI should only be updated from main thread:

dispatch_async(dispatch_get_main_queue()) {    self.tableView.reloadData()}

Update. In Swift 3 and later use:

DispatchQueue.main.async {    self.tableView.reloadData()}


You can also reload UITableView like this

self.tblMainTable.performSelectorOnMainThread(Selector("reloadData"), withObject: nil, waitUntilDone: true)


With Swift 3 use

DispatchQueue.main.async {    self.tableView.reloadData()}