【问题标题】:Swiftui Error: Type of expression is ambiguous without more contextSwiftui 错误:表达式类型不明确,没有更多上下文
【发布时间】:2019-10-17 20:47:15
【问题描述】:

我正在使用电子邮件身份验证设置 Firebase,我从网站复制源代码,他们在该网站上使用以下代码,但他们没有提及有关此错误的任何内容。

我已经尝试过 SO 和 GitHub 上的所有问题,但似乎没有一个有效。

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")

        }
    }
}

if 语句中间的那一行给了我以下错误:

Text("一个错误")

Type of expression is ambiguous without more context

【问题讨论】:

  • 那么error从何而来?
  • 我的意思是变量,为什么您不能在将错误消息发布到此处之前对其进行清理?

标签: ios swift swiftui


【解决方案1】:

看起来这是一个旧的 SwiftUI 代码。从那时起,TextField 的占位符参数发生了一些变化。

改成:

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")
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    相关资源
    最近更新 更多