SwiftUI:为什么 ForEach($strings) (text: Binding<String>) 不构建? [英] SwiftUI: Why does ForEach($strings) (text: Binding<String>) not build?
问题描述
我有一个 ForEach
它接受一个 Binding<[String]> 并且它用 Xcode11 beta5 编译得很好,但是用 beta6 它说表达式类型不明确,没有更多上下文
在 ForEach
内的 Text("...")
上,我找不到错误.是不是我不能再迭代这样的绑定了?
I have a ForEach
which takes a Binding<[String]> and it compiled with Xcode11 beta5 fine but with beta6 it says Type of expression is ambiguous without more context
on the Text("...")
inside the ForEach
and I can't find the mistake. Is it that I can't iterate over such a binding anymore?
struct ForEachItem1: View {
@Binding var items: [String]
var body: some View {
ForEach($items) { item in
Text("Hello world") // Type of expression is ambiguous without more context
}
}
}
struct ForEachItem2: View {
@Binding var items: [String]
var body: some View {
ForEach($items) { (item: Binding<String>) in
Text("Hello world") // Type of expression is ambiguous without more context
}
}
}
推荐答案
Binding
到 Collection
的条件一致性已被删除(有关弃用通知,请参阅 Xcode11 Beta5 发行说明).在以后的发行说明/版本中找不到.
The conditional conformance of Binding
to Collection
was removed (see Xcode11 Beta5 Release Notes for deprecation notice). It can't be found in later release notes/releases.
这篇关于SwiftUI:为什么 ForEach($strings) (text: Binding<String>) 不构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!