Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created June 12, 2022 21:48
Show Gist options
  • Select an option

  • Save sturdysturge/cb94f91f117d472f798bac245d13081e to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/cb94f91f117d472f798bac245d13081e to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var displayedText: String?
@State var inputText: String = ""
var body: some View {
Form {
Section("Input") {
TextField("Write here", text: $inputText)
Button("Set text") {
displayedText = inputText
}
}
Section("Displayed Text") {
if let displayedText {
Text(displayedText)
} else {
Color.clear
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment