注册通知
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "AuthSuccessNotification"), object: nil)
监听通知
NotificationCenter.default.addObserver(self, selector:#selector(ViewController.pageJump), name: NSNotification.Name(rawValue: "AuthSuccessNotification"), object: nil)
销毁通知
deinit {
NotificationCenter.default.removeObserver(self)
}
- deallco方法改成了deinit
- 一定要注意线程问题
本文介绍了如何使用Swift语言实现注册通知、监听通知及销毁通知的功能。通过NSNotification.Name(rawValue:AuthSuccessNotification)完成注册与监听的过程,并确保在deinit中移除观察者避免内存泄漏。
3912

被折叠的 条评论
为什么被折叠?



