Reputation: 11107
I have a simple NSNotification
set up on my Swift project.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "serviceAccessChanged", name:"LocationAccessChangedNotification", object: nil)
I've also tried...
NSNotificationCenter.defaultCenter().addObserver(self, selector: "serviceAccessChanged:", name:"LocationAccessChangedNotification", object: nil)
The method called looks like so.
private func serviceAccessChanged() {
println("serviceAccessChanged")
}
When the notification is made I receive the following error.
-[CoolApp.HomeViewController serviceAccessChanged]: unrecognized selector sent to instance 0x7fc91324bba0
What's wrong and how do I fix this?
Upvotes: 1
Views: 801
Reputation: 794
Just mark your private method with @objc
@objc private func serviceAccessChanged() {
println("serviceAccessChanged")
}
Upvotes: 1
Reputation: 57060
Private functions are not exposed to Objective C, and this is why you get this exception. Make this method accessible, and use the serviceAccessChanged
selector.
Upvotes: 3