Created
December 9, 2024 13:18
-
-
Save mbrandonw/ecf1a4493b691fd751b558ce787f6aa5 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
import SwiftUI | |
class Counter { | |
var count = 0 | |
} | |
extension EnvironmentValues { | |
@Entry var counter = Counter() | |
} | |
struct ContentView: View { | |
@Environment(\.counter) var counter | |
var body: some View { | |
Form { | |
Text("\(counter.count)") | |
Button("Increment") { | |
counter.count += 1 | |
print(counter.count) | |
} | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment