Xcode给了我一条错误消息,上面写着:
“无法推断复杂的闭包返回类型;请添加显式类型以消除歧义。”
我不知道该怎么办。我在StackOverflow上找到了一些带有SwiftUI的TextFields的其他代码示例,但仍然得到相同的错误。
struct TextFieldExample : View {
@State var email: String = "Enter email address"
var body: some View {
VStack {
TextField($email)
Text("Your email is \(email)!")
}
}
}
struct ButtonTextField : View {
@State var text: String = ""
var body: some View {
HStack {
TextField($text,
placeholder: Text("type something here..."))
Button(action: {
// Closure will be called once user taps your button
print(self.$text)
}) {
Text("SEND")
}
}
}
}
预期结果=工作TextField实际结果= Xcode中的错误
https://stackoverflow.com/questions/56568951
复制相似问题