//通知名称常量
let NotifyMsgRecvName = NSNotification.Name(rawValue:"notifyMsgRecvName")
//发送通知
NotificationCenter.default.post(name:NotifyMsgRecvName, object: nil, userInfo: notification.userInfo)
//接受通知监听
NotificationCenter.default.addObserver(self, selector:#selector(didMsgRecv(notification:)),
name: NotifyMsgRecvName, object: nil)
//通知处理函数
func didMsgRecv(notification:NSNotification){
print("didMsgRecv: \(notification.userInfo)")
}
销毁通知
deinit {
NotificationCenter.default.removeObserver(self)
}