NSObject+Sweeter.swift 694 B

12345678910111213141516171819
  1. //
  2. // NSObject+Sweeter.swift
  3. //
  4. // Created by Yonat Sharon on 2019-02-08.
  5. //
  6. import Foundation
  7. public extension NSObject {
  8. /// Sweeter: Post a local notification using `NotificationCenter.default`.
  9. func notify(_ notificationName: Notification.Name, userInfo: [AnyHashable: Any]? = nil) {
  10. NotificationCenter.default.post(name: notificationName, object: self, userInfo: userInfo)
  11. }
  12. /// Sweeter: Respond to a local notification from `NotificationCenter.default`.
  13. func observeNotification(name: Notification.Name, selector: Selector, object: Any? = nil) {
  14. NotificationCenter.default.addObserver(self, selector: selector, name: name, object: object)
  15. }
  16. }