Last active
May 23, 2020 21:50
-
-
Save Plnda/536774890c180ff3f708279a77440d1e 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
@propertyWrapper | |
struct Injected<Service> { | |
typealias DelayedInjection = () -> Service | |
var service: Service? | |
var delayed: DelayedInjection? | |
init() { | |
delayed = { Dependencies.main.resolve() } | |
} | |
var wrappedValue: Service { | |
mutating get { | |
if let service = service { | |
return service | |
} else if let delayed = delayed { | |
service = delayed() | |
return service! | |
} else { | |
fatalError() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment