【发布时间】:2020-03-22 06:42:56
【问题描述】:
我正在使用带有 SwiftUI 的 Xcode 11.3.1。
这段代码可以正常工作
struct ContentView: View {
var body: some View {
VStack {
ForEach(1...5, id: \.self) { index in
Text("\(index) of coffee.")
}
}
}
}
为什么?
struct ContentView: View {
var body: some View {
VStack {
ForEach(1...5, id: \.self) { index in
if index == 1 {
Text("Cup of coffee.")
} else {
Text("\(index) cups of coffee")
}
}
}
}
}
错误信息是:
无法推断复杂的闭包返回类型;添加显式类型 消除歧义。
【问题讨论】:
标签: swiftui