//观察者注册通知
let notName = Notification.Name(rawValue: "test")
NotificationCenter.default.addObserver(self, selector: #selector(self.reloadData), name: notName, object: nil)
//观察者接收到消息后进行处理
@objc func reloadData(not: Notification) {
not.userInfo 传递过来的信息字典类型
}
//发出通知,传递值
NotificationCenter.default.post(name: NSNotification.Name("test"), object: self, userInfo: ["post":"ttt"])
//记得在注册通知的时候销毁
deinit {
let notName = Notification.Name(rawValue: "test")
NotificationCenter.default.removeObserver(self, name: notName, object: nil)
}