我需要在项目中添加观察值,但是由于与我一起使用的管理器不允许我在函数中使用@objc,因此我是否可以不使用@objc而使用此函数?
func createObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(self.updatedata(notification:)),
name: Notification.Name(rawValue: updateNotificationKey), object: nil)
}
@objc dynamic func updatedata(notification: NSNotification) {
updateDataIcon()
}
您的帮助将不胜感激。
您可以将其与内联块一起使用
NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: updateNotificationKey) , object: nil, queue: .main) { [weak self] notification in
}