Swiftui 无法推断复杂的闭包返回类型;添加显式类型以消除自定义文本字段的歧义
我正在尝试接收文本字段文本并将其发送到另一个结构。但是得到这个错误。 另外,当我试图调用…Xcode中的.onReceive(Just(text)}数据时,我不理解Just是什么Swiftui 无法推断复杂的闭包返回类型;添加显式类型以消除自定义文本字段的歧义,swiftui,textfield,Swiftui,Textfield,我正在尝试接收文本字段文本并将其发送到另一个结构。但是得到这个错误。 另外,当我试图调用…Xcode中的.onReceive(Just(text)}数据时,我不理解Just是什么 struct CardInfo : View { @State var creditCard : CreditCard @State var isSaved: Bool = false @State private(set) var text = "" var body: some View {
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()
}
}
您不能在状态上使用
。在接收时,您需要publisher,如Just
,它是在组合框架中定义的,因此您需要导入它
import Combine
...
CustomTextField(data: $text, tFtext: "Kartin Uzerindeki Isim", tFImage: "user")
.textContentType(.givenName)
.onReceive(Just(text)) { data in
creditCard.cardOwnerName = text
}
它结束了错误,但当我在其中一个文本字段中添加一些文本时,其他人也在复制所有的字母。