Skip to content

Instantly share code, notes, and snippets.

@Abeansits
Created May 12, 2017 17:48
Show Gist options
  • Save Abeansits/d4b342c314e1cd2ec336aaae13b26c3e to your computer and use it in GitHub Desktop.
Save Abeansits/d4b342c314e1cd2ec336aaae13b26c3e to your computer and use it in GitHub Desktop.
protocol FirstDependency {}
protocol SecondDependency {}
protocol ThirdDependency {}
protocol HasFirstDependency {
var first: FirstDependency { get }
}
protocol HasSecondDependency {
var second: SecondDependency { get }
}
protocol HasThirdDependency {
var third: ThirdDependency { get }
}
class RealFirstDependency: FirstDependency {}
class RealSecondDependency: SecondDependency {}
class RealThirdDependency: ThirdDependency {}
struct AppDependencies: HasFirstDependency, HasSecondDependency, HasThirdDependency {
var first: FirstDependency
var second: SecondDependency
var third: ThirdDependency
}
class SomeObject {
typealias Dependencies = HasFirstDependency & HasSecondDependency
init(dependencies: Dependencies) {
self.dependencies = dependencies
}
var dependencies: Dependencies
}
let appDependencies = AppDependencies(
first: RealFirstDependency(),
second: RealSecondDependency(),
third: RealThirdDependency()
)
let object = SomeObject(dependencies: appDependencies)
print(object.dependencies.first)
print(object.dependencies.second)
print(object.dependencies.third) // Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment