Created
October 5, 2020 16:22
-
-
Save wizard1066/a13d8358114b78ba478a240f646892d1 to your computer and use it in GitHub Desktop.
variable.swift6
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
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