Skip to content

Instantly share code, notes, and snippets.

@tanduynguyen
Last active January 5, 2017 05:32
Show Gist options
  • Save tanduynguyen/deae26fef0fb71134865317ed68e00ad to your computer and use it in GitHub Desktop.
Save tanduynguyen/deae26fef0fb71134865317ed68e00ad to your computer and use it in GitHub Desktop.
The good way to work with NotificationCenter on Swift 3
enum Notifications: String {
case DidLogin
case DidLogout
case AddToCart
func post(object: AnyObject? = nil) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: self.rawValue), object: object)
}
func register(_ observer: Any, selector aSelector: Selector) {
NotificationCenter.default.addObserver(observer, selector: aSelector, name: NSNotification.Name(rawValue: self.rawValue), object: nil)
}
}
// Notifications.DidLogin.post()
// Notifications.DidLogin.register(self, selector: #selector(showUserInfo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment