Created
October 26, 2020 22:04
-
-
Save mykolaharmash/06fe28006cfa1588c41b19e386846bf2 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 | |
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