swift3中的通知进行了少许改变,仅此做一下记录
发出通知
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 ")