Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created October 5, 2020 16:22
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 wizard1066/a13d8358114b78ba478a240f646892d1 to your computer and use it in GitHub Desktop.
Save wizard1066/a13d8358114b78ba478a240f646892d1 to your computer and use it in GitHub Desktop.
variable.swift6
struct ContentView: View {
@State var redraw: Int = 0
var body: some View {
SwiftUIView10(refresh: $redraw)
.onTapGesture {
print("foo \(redraw)")
redraw += 1
}
}
}
struct SwiftUIView10: View {
@Binding var refresh:Int
@State var greeting: String = "X"
var body: some View {
Text(greeting)
.onChange(of: refresh) { ( newValue ) in
print("newValue \(newValue)")
switch newValue {
case 1:
greeting = "Hello, World!"
default:
greeting = "Next, Word!"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment