Skip to content

Instantly share code, notes, and snippets.

@peatiscoding
Created December 4, 2016 03:34
Show Gist options
  • Save peatiscoding/38b0436232b6ff3575877c39df659871 to your computer and use it in GitHub Desktop.
Save peatiscoding/38b0436232b6ff3575877c39df659871 to your computer and use it in GitHub Desktop.
// 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);
@peatiscoding
Copy link
Author

@erolando
Copy link

erolando commented Sep 7, 2018

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