不使用选择器添加观察者

Add observer without using selector

我需要在我的项目中添加 observes,但由于与我合作的经理不让我在函数中使用 @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 
   // to do 
}