Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@State and visibility toggle
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