How to use @State to see changes in same view

import SwiftUI

struct ContentView: View {

    @State var firstname: String

    var body: some View {
        VStack(alignment: .center) {
            Text("FirstView")
            TextField("enter name", text: $firstname)
            Text(firstname)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView(firstname: "")
    }
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s