Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created June 23, 2020 10:59
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 anupamchugh/b8b1f474fe2278ee194a28baf4901c25 to your computer and use it in GitHub Desktop.
Save anupamchugh/b8b1f474fe2278ee194a28baf4901c25 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var currentText: String = "Hi How are you?"
@State var clearText: Bool = false
var body: some View {
VStack{
TextEditor(text: $currentText)
.onChange(of: clearText) { value in
if clearText{
currentText = ""
}
}
Button(action: {clearText = true}, label: {
Text("Clear Text Editor")
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment