Swift 3.0 通知的注册,监听及销毁

时间:2022-08-30 15:53:27

注册通知

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)
}
  1. deallco方法改成了deinit
  2. 一定要注意线程问题