Reputation: 3878
func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: Any?)
This function needs the observer to be some object but while setting static methods as the selector.
This answer explains how to set selector and observer when the selector is an instance method.
Upvotes: 4
Views: 1380
Reputation: 3878
We need set YourClass.self
as the observer. In this way -
NotificationCenter.default.addObserver(YourClass.self, selector: #selector(YourClass.yourStaticMethod), name: NSNotification.Name.BlahBlah, object: nil)
Upvotes: 9