Skip to content

Instantly share code, notes, and snippets.

@andr-ec
Created June 9, 2019 20:36
Show Gist options
  • Save andr-ec/f22a97ec89dfdd6488f6ade3d6c44ce1 to your computer and use it in GitHub Desktop.
Save andr-ec/f22a97ec89dfdd6488f6ade3d6c44ce1 to your computer and use it in GitHub Desktop.
SwiftUI Counter
import SwiftUI
struct ContentView : View {
@State var counter = 0
var body: some View {
VStack{
Text("\(counter)")
HStack {
Button(action: onAdd){Text("Add")}
Button(action: onMinus){Text("Minus")}
}
}
}
func onAdd() {
counter += 1
}
func onMinus() {
counter -= 1
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment