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

注册通知

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. 一定要注意线程问题

你可能感兴趣的:(iOS,代码片段,Swift-3-0,通知)