Skip to content

Instantly share code, notes, and snippets.

@mykolaharmash
Created October 26, 2020 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mykolaharmash/06fe28006cfa1588c41b19e386846bf2 to your computer and use it in GitHub Desktop.
Save mykolaharmash/06fe28006cfa1588c41b19e386846bf2 to your computer and use it in GitHub Desktop.
import SwiftUI
struct Counter: View {
@State var count: Int = 0
init() {
print("Counter Created")
}
var body: some View {
VStack {
Text(String(count))
Button("+ 1", action: { count = count + 1 })
}
}
}
struct ContentView: View {
@State var random = 0
var body: some View {
VStack {
Counter()
Spacer()
Text(String(random))
Button("Random", action: { random = Int.random(in: 1...10) })
}.font(.system(size: 26))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment