Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // DependencyInjectable.swift
- //
- import Foundation
- /**
- Supports property injection.
- This is useful when constructor injection isn't possible, like in storyboard-based UIViewController subclasses.
- 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.
- ```swift
- private var myProperty: MyType! {
- willSet {
- assert(newValue != nil)
- }
- }
- ```
- */
- protocol DependencyInjectable: class {
- /// The type of the dependencies
- ///
- /// Use a tuple to support multiple dependencies.
- ///
- associatedtype DependencyType
- /// Inject the dependencies
- ///
- /// Call this method immediately after the class is instantiated, before assertDependencies() is called.
- ///
- func inject(_: DependencyType)
- /// Ensure that the dependencies are set
- ///
- /// In a UIViewController subclass this is typically called from viewDidLoad
- ///
- func assertDependencies()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement