Created
March 20, 2020 21:09
-
-
Save paulz/21a1c691242d5e3ce8ea75f2930b89c6 to your computer and use it in GitHub Desktop.
Dependency Injection For Objective C and Swift hybrid project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct ChainedResolver: ResolveDependency { | |
| public func resolve<Service>(_: Service.Type, name: String?) -> Service? { | |
| child.resolve(name: name) ?? parent.resolve(name: name) | |
| } | |
| let child, parent: ResolveDependency | |
| public init(child: ResolveDependency, parent: ResolveDependency) { | |
| self.child = child | |
| self.parent = parent | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public protocol ResolveDependency { | |
| func resolve<Service>(_: Service.Type, name: String?) -> Service? | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very helpful while migrating Objective-C code to Swift. Swift classes were able to access Objective-C dependencies without importing them via bridging headers.