I believe I\'m having an issue where my closure is happening on a background thread and my UITableView isn\'t updating fast enough. I am making a call to a REST service and
You can also reload UITableView like this
self.tblMainTable.performSelectorOnMainThread(Selector("reloadData"), withObject: nil, waitUntilDone: true)
SWIFT 3:
OperationQueue.main.addOperation ({
self.tableView.reloadData()
})
You can also update the main thread using NSOperationQueue.mainQueue()
. For multithreading, NSOperationQueue is a great tool.
One way it could be written:
NSOperationQueue.mainQueue().addOperationWithBlock({
self.tableView.reloadData()
})
Update: DispatchQueue is the way to go for this
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()
}
With Swift 3 use
DispatchQueue.main.async {
self.tableView.reloadData()
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
to reflect in UI the data should be in main Thread. So, usage of this method will bring the data to main thread and it will be make available to reflect in UI.