Created
January 11, 2024 20:37
-
-
Save hasanalisiseci/b70c972e23ebaa4c1dec61a9b8953a1c 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
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