Skip to content

Instantly share code, notes, and snippets.

@nalexn
Created December 21, 2019 13:08
Show Gist options
  • Save nalexn/22a91684b388f50452218e42e51c1449 to your computer and use it in GitHub Desktop.
Save nalexn/22a91684b388f50452218e42e51c1449 to your computer and use it in GitHub Desktop.
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