On change in textField value will change in SwiftUI

100rabhcsmc

Saurabh Chavan

Posted on March 23, 2023

On change in textField value will change in SwiftUI

When we change in the textField then value whatever get then this value will change in swift

the code are as follow:

import SwiftUI

struct User{
    var firstName = "Saurabh"
    var lastName = "Chavan"
}

struct ContentView: View {
    @State private var Users = User()
    var body: some View{
        VStack{
             Text("\(Users.firstName)  \(Users.lastName)")

            TextField("First Name", text: $Users.firstName)

            TextField("Last Name", text: $Users.lastName)
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

💖 💪 🙅 🚩
100rabhcsmc
Saurabh Chavan

Posted on March 23, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related