Created
June 9, 2019 20:36
-
-
Save andr-ec/f22a97ec89dfdd6488f6ade3d6c44ce1 to your computer and use it in GitHub Desktop.
SwiftUI Counter
This file contains hidden or 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 | |
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