In Swift 3, to register a notification, I can do the following:
NotificationCenter.default.addObserver(self, selector:
func n1(notification: Notification){
print("123")
}
NotificationCenter.default.addObserver(self, selector:
func n2(notification: Notification){
print("456")
}
However, in Xcode 9.0 beta 2 (Swift 4.0), when I register a notification this way, the object method must have a prefix @objc, why? What is the best practice for using Notices?
Argument of '#selector' refers to instance method 'n1(notification:)' that is not exposed to Objective-C
//Add '@objc' to expose this instance method to Objective-C
@objc func n1(notification: Notification){
print("123")
}
@objc func n2(notification: Notification){
print("456")
}
source
share