Created
October 27, 2020 15:17
-
-
Save mykolaharmash/bc2608096cc48a6e0b418a0178a89151 to your computer and use it in GitHub Desktop.
@State and visibility toggle
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 CounterView: View { | |
@State var count = 0 | |
var body: some View { | |
Text(String(count)) | |
Button("+ 1", action: { count = count + 1 }) | |
} | |
} | |
struct ContentView: View { | |
@State var visible = true | |
var body: some View { | |
VStack { | |
if (visible) { | |
CounterView() | |
} | |
Spacer() | |
Button("Toggle", action: { visible.toggle() }) | |
}.font(.system(size: 26)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment