美文网首页
swift 3.0通知的基本用法

swift 3.0通知的基本用法

作者: 渴望平静生活的上班族 | 来源:发表于2017-09-27 09:16 被阅读0次

//通知名称常量

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)

}

相关文章

网友评论

      本文标题:swift 3.0通知的基本用法

      本文链接:https://www.haomeiwen.com/subject/wvpyextx.html