Skip to content

Instantly share code, notes, and snippets.

@lammertw
Created April 3, 2021 16:35
Show Gist options
  • Save lammertw/f051201fc39f92ff3c398c41621873fe to your computer and use it in GitHub Desktop.
Save lammertw/f051201fc39f92ff3c398c41621873fe to your computer and use it in GitHub Desktop.
class ObservableCounter: ObservableObject {
@Published var count = 0
func increment() {
count += 1
}
}
@main
struct MyApp: App {
@ObservedObject var counter = ObservableCounter()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(counter)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment