I want to set text for Textfield
in SwiftUI
on button clicked. I tried using @State
variable but its giving error
Try Below code (tested in Xcode: 11.2.1)
struct ContentView: View {
@State var name: String = ""
var body: some View {
VStack {
TextField("Please enter", text: $name)
Button(action: {
self.name = "Hello text"
}) {
Text("Press")
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With