Skip to content

Instantly share code, notes, and snippets.

@OskarGroth
Created March 2, 2023 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OskarGroth/296d2705f9fa2861f6e7e257d1ff33ec to your computer and use it in GitHub Desktop.
Save OskarGroth/296d2705f9fa2861f6e7e257d1ff33ec to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State var flip = false
var body: some View {
VStack {
Toggle("Refresh", isOn: $flip)
.toggleStyle(.switch)
StateSubView(model: .init(source: "State subview"))
ObservedSubView(model: .init(source: "Observed subview"))
}
.padding()
}
}
struct StateSubView: View {
@StateObject var model: Model
var body: some View {
Color.clear
}
}
struct ObservedSubView: View {
@ObservedObject var model: Model
var body: some View {
Color.clear
}
}
class Model: ObservableObject {
init(source: String) {
print("Init Model from \(source)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment