I have an app that is in Object-C and I'm trying to pass it to Swift, but I'm having some problems, one of them is NSNotification that is not working.
In object-C, I'm using it as follows:
- (void)viewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[super viewDidLoad];
}
- (void) applicationDidEnterBackground:(NSNotification*)notification {
NSLog(@"Entro em back");
}
In swift I'm trying the following way, but it's not calling the function:
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationDidEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
}
func applicationDidEnterBackground() {
println("Entro em back")
}
In my case, I need to load an information into NSUserDefaults when the app loads and saves the information changed by the user when the app goes into the background.
Note: I can not access either function.