If you're referencing a selector from your own class, there should be no difference, since self
points to Aclass
.
If you are referencing a selector from another class, you must explicitly call Aclass.someMethod
, since the selector is not on self
but on a different object.
class MyClass: NSObject {
func someFunc() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.someOtherFunc(_:)), name: "someEvent", object: nil)
}
func someOtherFunc(notification: AnyObject) {
//
}
}
class OtherClass: NSObject {
func anotherFunc() {
let myInstance = MyClass()
NSNotificationCenter.defaultCenter().addObserver(myInstance, selector: #selector(MyClass.someOtherFunc(_:)), name: "someEvent", object: nil)
}
}