1

I want to get text from a textfield.

My var is Entfernung:

 @State var entfernung = ""

And here is my HStack where the TextField is in:

HStack{
                Text(LocalizedStringKey("entfernung")).font(.title).bold().padding(.leading, 15).padding(.top, 30)

                TextField("Username", text: $entfernung)
                    .font(.system(size: 20)).padding(.horizontal).background(Color.green)
                Text(entfernung)           
                Text(LocalizedStringKey("entfernung")).font(.title).bold().padding(.leading, 15).padding(.top, 30)
            }

But I get the error that I have to put self. infront of $entfernung. But when I change the code I am not able to edit the Textfield in my program.

HStack{
                    Text(LocalizedStringKey("entfernung")).font(.title).bold().padding(.leading, 15).padding(.top, 30)

                    TextField("Username", text: self.$entfernung)
                        .font(.system(size: 20)).padding(.horizontal).background(Color.green)
                    Text(self.entfernung)     
                    Text(LocalizedStringKey("entfernung")).font(.title).bold().padding(.leading, 15).padding(.top, 30)
                }

Does anyone know what my problem is?

0 Answers0