You can write a custom UIViewController that listens to notifications, and then make all other UIViewControllers subclass it. That way they all can listen, and you do not duplicate code. I think this should work:
class ListeningViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("derp"), name: "herp", object: nil)
}
func derp() {
print("herp-derp")
}
}
class FunctionalViewController: ListeningViewController {
override func derp() {
print("i can also derp")
}
}
or you can write a UIViewController extension:
extension UIViewController {
public func startListenintToNotifications() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("derp"), name: "herp", object: nil)
}
func derp() {
print("herp-derp")
}
}
And just call the startListeningToNotificationsMethod once in every ViewController