Ios SwiftUI:通用参数';C0和x27;无法推断
我一直在使用这段代码,并且不断出现以下错误:“”无法推断通用参数“C0”“”此外,在我的Ios SwiftUI:通用参数';C0和x27;无法推断,ios,swift,swiftui,Ios,Swift,Swiftui,我一直在使用这段代码,并且不断出现以下错误:“”无法推断通用参数“C0”“”此外,在我的HStack中包含这行代码时,它在调用函数“buildBlock”(SwiftUI.ViewBuilder)时会显示“In call to function”: self.userData.tempBatchUnit = productName 我不知道为什么。没有那行代码,代码就可以正常工作。非常感谢 struct enterProductUnitView: View { @Environment
HStack
中包含这行代码时,它在调用函数“buildBlock”(SwiftUI.ViewBuilder)时会显示“In call to function”:
self.userData.tempBatchUnit = productName
我不知道为什么。没有那行代码,代码就可以正常工作。非常感谢
struct enterProductUnitView: View {
@EnvironmentObject var userData: UserData
@State var productName: String = ""
var body: some View {
VStack {
HStack { // error Generic parameter 'C0' could not be inferred
Text("Product Unit:")
.font(.headline)
Spacer()
NavigationLink(destination: InstructionsView(desireInstructions: "Product Unit")) {
Text("?")
}
}
Text("ex: bags of popcorn, jars of jam etc.")
.font(.subheadline)
TextField("Enter here", text: $productName)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.padding(.leading)
self.userData.tempBatchUnit = productName
}
}
}
删除以下行-在
body
view builder中不允许该行
self.userData.tempBatchUnit = productName
我想它应该在中.onCommit
TextField("Enter here", text: $productName, onCommit: {
self.userData.tempBatchUnit = self.productName
})
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.padding(.leading)
删除以下行-在
body
view builder中不允许该行
self.userData.tempBatchUnit = productName
我想它应该在中.onCommit
TextField("Enter here", text: $productName, onCommit: {
self.userData.tempBatchUnit = self.productName
})
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.padding(.leading)