微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法推断复杂的闭包返回类型;添加显式类型以消除自定义TextField的歧义

如何解决无法推断复杂的闭包返回类型;添加显式类型以消除自定义TextField的歧义

我正在尝试接收文本字段文本并将其发送到另一个结构。但是得到这个错误。 同样,当我尝试调用.onRecieve(Just(text)}数据时,... Xcode无法理解什么是正义。

struct CardInfo : View {
@State var creditCard : CreditCard
@State var isSaved: Bool = false
@State private(set) var text = ""
var body: some View {
    vstack {
        CustomTextField(data: $text,tFtext: "Kartin Uzerindeki Isim",tFImage: "user")
            .textContentType(.givenname)
            .onReceive(text) { data in
                creditCard.cardOwnerName = text
        }
        CustomTextField(data: $text,tFtext: "Kredi Kart Numarasi",tFImage: "credit")
            .textContentType(.oneTimeCode)
            .keyboardType(.numberPad)
        HStack {
            CreditCardDateTextField(tFtext: "",tFImage: "date")
                .textContentType(.creditCardNumber)
            Spacer()
            Text("")
                .overlay(
                    Rectangle()
                        .frame(width: 70,height: 53))
            Text("|")
                .foregroundColor(.black)
            CustomTextField(data: $text,tFtext: "CCV",tFImage: "")
                .textContentType(.creditCardNumber)
        }
        .foregroundColor(Color(#colorLiteral(red: 0.9647058824,green: 0.9725490196,blue: 0.9882352941,alpha: 1)))
        Group {
            CustomTextField(data: $text,tFtext: "Kart Ismi",tFImage: "cardEdit")
            Spacer()
            Button(action: {
                self.isSaved.toggle()
            },label: { CustomButton(title: "Kaydet",icon: .none,status: .enable)
            })
        }
    }
    .edgesIgnoringSafeArea(.all)
    .padding()
}

}

enter image description here

解决方法

您不能在状态上使用.onReceive,需要使用Just框架中定义的发布者,例如Combine,因此需要导入它。

import Combine

...

        CustomTextField(data: $text,tFtext: "Kartin Uzerindeki Isim",tFImage: "user")
            .textContentType(.givenName)
            .onReceive(Just(text)) { data in
                creditCard.cardOwnerName = text
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。