Created
January 11, 2024 20:31
-
-
Save hasanalisiseci/3948955969fa1cb14837cf71b07f828a 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
@Observable | |
class WeatherViewModel { | |
var currentTemperature: Double = -5.2 | |
var city: String = "Sivas" | |
var isSnowing: Bool = false | |
@ObservationIgnored var isRaining = false | |
} | |
@main | |
struct ObservableDemoApp: App { | |
@State var weatherVM = WeatherViewModel() | |
var body: some Scene { | |
WindowGroup { | |
WeatherView() | |
.environment(weatherVM) | |
} | |
} | |
} | |
struct WeatherView: View { | |
@State var weatherVM = WeatherViewModel() | |
var body: some View { | |
VStack { | |
Text("Current City: \(weatherVM.city)") | |
Text("°C: \(weatherVM.currentTemperature)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment