Skip to content

Instantly share code, notes, and snippets.

@mykolaharmash
Created October 27, 2020 15:17
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/bc2608096cc48a6e0b418a0178a89151 to your computer and use it in GitHub Desktop.
Save mykolaharmash/bc2608096cc48a6e0b418a0178a89151 to your computer and use it in GitHub Desktop.
@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