Created
November 4, 2019 04:05
-
-
Save fmo91/abc7497557a9567c14026d8f53d03959 to your computer and use it in GitHub Desktop.
This file contains 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
enum Dependencies { | |
// ... | |
final class Container { | |
// ... | |
func register(_ dependency: Any, for key: Dependencies.Name = .default) { | |
dependencies.append((key: key, value: dependency)) | |
} | |
func resolve<T>(_ key: Dependencies.Name = .default) -> T { | |
return (dependencies | |
.filter { (dependencyTuple) -> Bool in | |
return dependencyTuple.key == key | |
&& dependencyTuple.value is T | |
} | |
.first)?.value as! T | |
} | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment