Skip to content

Instantly share code, notes, and snippets.

@hasanalisiseci
Created January 11, 2024 20:37
Show Gist options
  • Save hasanalisiseci/b70c972e23ebaa4c1dec61a9b8953a1c to your computer and use it in GitHub Desktop.
Save hasanalisiseci/b70c972e23ebaa4c1dec61a9b8953a1c to your computer and use it in GitHub Desktop.
struct WeatherVMKey: EnvironmentKey {
static var defaultValue = WeatherViewModel()
}
extension EnvironmentValues {
var weatherVM: WeatherViewModel {
get { self[WeatherVMKey.self] }
set { self[WeatherVMKey.self] = newValue }
}
}
struct WeatherView: View {
@Environment(\.weatherVM) var weatherVM
var body: some View {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment