Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. //
  2. // DependencyInjectable.swift
  3. //
  4.  
  5. import Foundation
  6.  
  7. /**
  8. Supports property injection.
  9.  
  10. This is useful when constructor injection isn't possible, like in storyboard-based UIViewController subclasses.
  11.  
  12. This lets you to use private implicitily unwrapped optional properties in the conforming object instead of exposing optional properties that always need to be unwrapped before use. The additional assert in willSet is to ensure that the property doesn't get set to nil which would break the guarantee that we're trying to establish with this protocol.
  13.  
  14. ```swift
  15. private var myProperty: MyType! {
  16. willSet {
  17. assert(newValue != nil)
  18. }
  19. }
  20. ```
  21. */
  22. protocol DependencyInjectable: class {
  23.  
  24. /// The type of the dependencies
  25. ///
  26. /// Use a tuple to support multiple dependencies.
  27. ///
  28. associatedtype DependencyType
  29.  
  30. /// Inject the dependencies
  31. ///
  32. /// Call this method immediately after the class is instantiated, before assertDependencies() is called.
  33. ///
  34. func inject(_: DependencyType)
  35.  
  36. /// Ensure that the dependencies are set
  37. ///
  38. /// In a UIViewController subclass this is typically called from viewDidLoad
  39. ///
  40. func assertDependencies()
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement