4
func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: Any?)

此功能需要观察者是某个对象,但同时将静态方法设置为选择器。

This answer explains how to set selector and observer when the selector is an instance method .

4

1 回答 1

8

我们需要设置YourClass.self为观察者。这样 -

NotificationCenter.default.addObserver(YourClass.self, selector: #selector(YourClass.yourStaticMethod), name: NSNotification.Name.BlahBlah, object: nil)
于 2017-01-31T09:03:03.507 回答