NotificationCenter.default.addObserver(self, selector:#selector(test), name:NSNotification.Name(rawValue:"isTest"), object:nil)
//实现通知监听方法
@objcfunctest(nofi :Notification){
letstr = nofi.userInfo!["post"]
print(String(describing: str!) +"this notifi")
}
//点击发送通知进行
overridefunctouchesBegan(_touches:Set, with event:UIEvent?) {
NotificationCenter.default.post(name:NSNotification.Name("isTest"), object:self, userInfo: ["post":"NewTest"])
}
//最后要记得移除通知
deinit{
/// 移除通知
NotificationCenter.default.removeObserver(self)
}
网友评论