Created
December 21, 2019 13:08
-
-
Save nalexn/22a91684b388f50452218e42e51c1449 to your computer and use it in GitHub Desktop.
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
struct AppState { | |
var value1: Int = 0 | |
var value2: Int = 0 | |
var value3: Int = 0 | |
} | |
extension AppState { | |
struct Injection: EnvironmentKey { | |
let appState: CurrentValueSubject<AppState, Never> | |
static var defaultValue: Self { | |
return .init(appState: .init(AppState())) | |
} | |
} | |
} | |
extension EnvironmentValues { | |
var injected: AppState.Injection { | |
get { self[AppState.Injection.self] } | |
set { self[AppState.Injection.self] = newValue } | |
} | |
} | |
let injected = AppState.Injection(appState: .init(AppState())) | |
let contentView = ContentView().environment(\.injected, injected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment