Apix_D
Apix_D

Reputation: 1101

Generic parameter 'C0' could not be inferred while TextField implementation

after some time without SwiftUI i try to do some basic stuff... implement a simple TextField and receive the failure message below..

Here is my code snippet.

struct ContentView: View {

@State private var name = String()
@State private var pw = String()
@State private var fileName = "Test"

var body: some View {
    NavigationView{
        ZStack{
            VStack{
              Spacer()
                VStack{
                    Image("user")
                        .resizable()
                        .frame(width: 100, height: 100)
                    Spacer()
                    Text("Hello User.")
                    Text("Please insert your Username and password")
                    .lineLimit(nil)
                }
            .padding()
                HStack{
                    Spacer()
                    Text("Username")
                        .font(.headline)
                    Spacer()
                    Text("Password")
                        .font(.headline)
                    Spacer()
                }
                HStack{
                    Spacer()
                    TextField($name, placeholder: Text("Name"))
                        .textFieldStyle(.roundedBorder)
                        .scaledToFit()
                    Spacer() 
                }
            }
        }
    }
}

I don't understand what the compiler wants me to do. Thanks for your help!

Upvotes: 0

Views: 57

Answers (1)

E.Coms
E.Coms

Reputation: 11531

The code on the TextField is either outdated or wrong:

  TextField("Name", text:$name )
                   .textFieldStyle(RoundedBorderTextFieldStyle())
                    .scaledToFit()

Upvotes: 1

Related Questions