I have a tab bar application and a tab whose view controller is controlled by a UITableView class. I have a class that is used to download data from the server that then sav
I think the easiest way to do what you want to do is use a delegate.
protocol UpdateDelegate {
func didUpdate(sender: Updates)
}
So in your updates class, where you want to refresh the table view you would call the delegates didUpdate function. (You will have to set the delegate before it starts the update for the method to be called.) The weak keyword is important, if it isn't there, neither of the classes will be GC'd, which will lead to memory leaks.
class Updates {
weak var delegate: UpdateDelegate?
...
//Indicates progress finished
self.delegate.didUpdate(self)
In your tableView class you would subscribe to that delegate by adding UpdateDelegate to the top of the class
class ConnectTableVC: UITableViewController, UpdateDelegate {
...
let updates = Updates()
updates.delegate = self
...
func didUpdate(sender: updates) {
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
}
I would recommend against using the NSNotificationCenter, the biggest reason is anyone anywhere can listen to the notification (which might be unlikely in your case, but it is still worth noting).