swift3中的通知進(jìn)行了少許改變,僅此做一下記錄
發(fā)出通知
NotificationCenter.default.post(name: NSNotification.Name(rawValue: PSNOTIFICATION_MESSAGE_SHOULDSHOW), object: nil, userInfo: [PSNOTIFICATION_BOOL_FOR_MESSAGESHOW : "YES"])
接收通知
NotificationCenter.default.addObserver(self, selector: #selector(receiveNewMessages(notifiacation:)), name: NSNotification.Name(rawValue: PSNOTIFICATION_MESSAGE_SHOULDSHOW), object: nil)
處理消息
func receiveNewMQMessages(notifiacation:NSNotification) {
let judge:Bool = (notifiacation.userInfo![PSNOTIFICATION_BOOL_FOR_MESSAGESHOW] as? String) == "YES" ? true:false;
if judge == true {
}else {
}
}
一切看上去沒什么不同,但是確實有一點不同,因為userInfo要求的key是AnyHashable類型的
let PSNOTIFICATION_BOOL_FOR_MESSAGESHOW :AnyHashable = AnyHashable.init("BOOLFORMESSAGESHOW ")