【问题标题】:How can I solve this "Unable to infer complex closure return type; add explicit type to disambiguate" error?如何解决此“无法推断复杂的闭包返回类型;添加显式类型以消除歧义”错误?
【发布时间】:2020-06-25 11:11:35
【问题描述】:

自从我在我的代码中包含了这行代码后,我就被报告了这个错误...

TextField("\(cellText)", text: Binding<String>(get: {
                        self.useB ? self.userCode : self.code
                    }, set: {
                        if self.useB == true {
                            self.userCode = ""
                        } else {
                            self.code = ""
                        }
                    }))

谁能帮我理解发生了什么?

【问题讨论】:

    标签: ios swift iphone swiftui uitextfield


    【解决方案1】:

    set:签名需要在内部指定或使用参数,不能省略

    这里是固定的变体(对于提供的快照)

    TextField("\(cellText)", text: Binding<String>(get: {
                            self.useB ? self.userCode : self.code
                        }, set: { _ in              // << if not used, specify it !!
                            if self.useB == true {
                                self.userCode = ""
                            } else {
                                self.code = ""
                            }
                        }))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多