DEV Community

Saurabh Chavan
Saurabh Chavan

Posted on

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay