ExtensionNotification.swift 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import Foundation
  2. extension Notification.Name {
  3. static let ReachabilityStateChanged = Notification.Name(
  4. rawValue: "ReachabilityStateChanged")
  5. static let HiddenStateChanged = Notification.Name(
  6. rawValue: "HiddenStateChanged")
  7. static let NoticePushed = Notification.Name(
  8. rawValue: "NoticePushed")
  9. static let WorkPushed = Notification.Name(
  10. rawValue: "WorkPushed")
  11. }
  12. extension Notification{
  13. typealias NotificationBlock = (Notification) -> Void
  14. static func registerNotification(name:NSNotification.Name, object:Any? = nil, queue:OperationQueue, block:@escaping NotificationBlock){
  15. NotificationCenter.default.addObserver(forName: name, object: object, queue: queue, using: block)
  16. }
  17. static func removeNotification(observer:Any){
  18. NotificationCenter.default.removeObserver(observer)
  19. }
  20. static func postNotification(name:NSNotification.Name, object:Any? = nil){
  21. NotificationCenter.default.post(name: name, object: object)
  22. }
  23. }