import SwiftUI
struct CounterView: View {
@State private var count = 0
var body: some View {
VStack(spacing: 20) {
Text("Counter: \(count)")
.font(.largeTitle)
.accessibilityLabel("Current count")
Button("Increase") {
count += 1
}
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
.accessibilityHint("Increases the counter by one")
}
.padding()
}
}
struct CounterView_Previews: PreviewProvider {
static var previews: some View {
CounterView()
}
}This app uses a @State variable called count to hold the current number. When the button is tapped, we increase count by 1. SwiftUI watches this @State variable and automatically updates the UI to show the new number. This is how state drives reactive UI updates: changing the state triggers the UI to refresh without extra code.
We also added accessibility labels and hints so screen readers can describe the UI clearly, making the app friendly for everyone.