Tomas Mota
Tomas Mota

Reputation: 679

Swiftui Error: Type of expression is ambiguous without more context

I'm setting up Firebase with Email authentication, I copying a source code from a website, on which they use the following code, but they do not mention anything about this error.

I have tried every question on SO and GitHub but none of them seem to work.

var body: some View {
    VStack {
        TextField($email, placeholder: Text("email address"))
        SecureField($password, placeholder: Text("Password"))
        if (error) {
            Text("An error")
        }
        Button(action: signIn) {
            Text("Signing in")

        }
    }
}

That line in the middle of the if statement is giving me the following error:

Text("An error")

Type of expression is ambiguous without more context

Upvotes: 1

Views: 1034

Answers (1)

Mojtaba Hosseini
Mojtaba Hosseini

Reputation: 119380

Seems like this is an old SwiftUI code. Placeholder argument of the TextField changed a bit since then.

change it to:

var body: some View {
    VStack {
        TextField("email address", text: $email)
        SecureField("Password", text: $password)
        if (error) {
            Text("Oh an error!")
        }
        Button(action: signIn) {
            Text("Signing in")
        }
    }
}

Upvotes: 1

Related Questions