NotificationCenter+Rx.swift 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // NotificationCenter+Rx.swift
  3. // SwiftBilibili
  4. //
  5. // Created by 罗文 on 2021/1/21.
  6. // Copyright © 2021年 罗文. All rights reserved.
  7. //
  8. import RxSwift
  9. enum BiliNotification: String {
  10. case netError
  11. case stopRotate
  12. case startRequest
  13. case endRequest
  14. var stringValue: String {
  15. return "Bilibili" + rawValue
  16. }
  17. var notificationName: NSNotification.Name {
  18. return NSNotification.Name(stringValue)
  19. }
  20. }
  21. extension NotificationCenter {
  22. static func post(customNotification name: BiliNotification,object: Any? = nil) {
  23. NotificationCenter.default.post(name: name.notificationName, object: object)
  24. }
  25. }
  26. extension Reactive where Base: NotificationCenter {
  27. func notification(custom name: BiliNotification,object: AnyObject? = nil) -> Observable<Notification>
  28. {
  29. return notification(name.notificationName, object: object)
  30. }
  31. }