Last active
January 5, 2017 05:32
-
-
Save tanduynguyen/deae26fef0fb71134865317ed68e00ad to your computer and use it in GitHub Desktop.
The good way to work with NotificationCenter on Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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