使用示例:
// 发送通知
NotificationCenter.default.post(name: NSNotification.Name.EndTopicSuccessNoti, object: nil)
// 添加通知监听
NotificationCenter.default.addObserver(self, selector: #selector(endTopicAction), name: NSNotification.Name.EndTopicSuccessNoti, object: nil)
extension Notification.Name {
/// 结束会话成功通知
static let EndTopicSuccessNoti = Notification.Name(rawValue:"EndTopicSuccess")
}
使用RxSwift
NotificationCenter.default.rx.notification(Notification.Name.EndTopicSuccessNoti, object: nil).subscribe(onNext: { (notification) in
...
}).disposed(by: disposeBag)
网友评论