NeedsDependency.swift 716 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // NeedsDependency.swift
  3. // Mastodon
  4. //
  5. // Created by Cirno MainasuK on 2021-1-27.
  6. //
  7. import UIKit
  8. import MastodonCore
  9. protocol NeedsDependency: AnyObject {
  10. var context: AppContext! { get set }
  11. var coordinator: SceneCoordinator! { get set }
  12. }
  13. extension UISceneSession {
  14. private struct AssociatedKeys {
  15. static var sceneCoordinator = "SceneCoordinator"
  16. }
  17. weak var sceneCoordinator: SceneCoordinator? {
  18. get {
  19. return objc_getAssociatedObject(self, &AssociatedKeys.sceneCoordinator) as? SceneCoordinator
  20. }
  21. set {
  22. objc_setAssociatedObject(self, &AssociatedKeys.sceneCoordinator, newValue, .OBJC_ASSOCIATION_ASSIGN)
  23. }
  24. }
  25. }