Skip to content

Instantly share code, notes, and snippets.

@hasanalisiseci
Created January 11, 2024 20:31
Show Gist options
  • Save hasanalisiseci/3948955969fa1cb14837cf71b07f828a to your computer and use it in GitHub Desktop.
Save hasanalisiseci/3948955969fa1cb14837cf71b07f828a to your computer and use it in GitHub Desktop.
@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