Skip to content

Instantly share code, notes, and snippets.

@leoneparise
Last active January 27, 2017 13:12
Show Gist options
  • Save leoneparise/c7b71524a75cd72b2db935ef9acb64e1 to your computer and use it in GitHub Desktop.
Save leoneparise/c7b71524a75cd72b2db935ef9acb64e1 to your computer and use it in GitHub Desktop.
extension NotificationCenter {
func post(_ notification:NotificationType, object:Any? = nil) {
post(name: notification.name, object: object, userInfo: notification.userInfo)
}
func addObserver<T:NotificationType>(forType type: T.Type, object obj: Any? = nil, queue: OperationQueue? = nil,
using block: @escaping (T?) -> Swift.Void) -> NSObjectProtocol {
return addObserver(forName: type.name, object: obj, queue: queue) {
block( type.init(notification: $0) )
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment