I am rewriting the class in Swift that I did in Objective-C, however, when I register my new Swift class as an observer, it does not respond to notifications sent to another object class c using NSNotificationCenter.
The code is as follows:
Grade A:
[[NSNotificationCenter defaultCenter] postNotificationName:REFRESH_UI object:nil];
Class B (objective-c):
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUI) name:REFRESH_UI object:nil];
- (void)refreshUI {
[self.tableView reloadData];}
Class B (fast)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "refreshUI", name:REFRESH_UI , object: nil)
func refreshUI() {
self.tableView.reloadData()
}
Class B works fine when writing in objective-c. What is wrong with my Swift code?
source
share