Created
December 4, 2016 03:34
-
-
Save peatiscoding/38b0436232b6ff3575877c39df659871 to your computer and use it in GitHub Desktop.
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
// Basic.swift | |
extension Notification.Name { | |
func post(object:Any? = nil, userInfo:[AnyHashable: Any]? = nil) { | |
NotificationCenter.default.post(self, object: object, userInfo: userInfo) | |
} | |
} | |
// DataModel.swift | |
extension Notification.Name { | |
static let AccountBalanceUpdated = Notification.Name("accountBalanceUpdated") | |
} | |
// Sample Usage .. | |
Notification.Name.AccountBalanceUpdated.post(myAccountObject); |
addObservers:
func addObserver(_ observer: Any, selector aSelector: Selector, object anObject: Any?) {
NotificationCenter.default.addObserver(observer, selector: aSelector, name: self, object: anObject)
}
func addObserver(forObject obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) {
NotificationCenter.default.addObserver(forName: self, object:obj, queue:queue, using: block)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For better explanation - see http://peatiscoding.me/geek-stuff/using-notification-name-swift-3/.