【发布时间】:2020-02-03 04:35:19
【问题描述】:
我正在使用 Xcode 11.3 和 Swift5 开发我的第一个 iOS 应用程序。
但我一直在使用 ForEach 视图。
我想使用 Foreach 将某些 struct 放入 ZStack 中,但仍然出现错误。
Error : Unable to infer complex closure return type; add explicit type to disambiguate
我不知道如何解决这个问题。你能帮帮我吗?
/* Struct I want to put in */
struct Verses: Identifiable{
var id: Int
var verse : Int
}
/* I want to load all values from struct using foreach in view. */
ZStack {
ForEach(controller.verses) { w in <- Here is where I get error.
Rectangle()
.foregroundColor(Color.white)
.cornerRadius(28)
.opacity(0.4)
.offset(x:0, y:68)
.frame(width:290, height:280)
CardView(date: w.date)
.gesture(DragGesture()
.onChanged({ (value) in
......
【问题讨论】:
-
能否将 Rectangle 和 CardView 放入另一个名为 Cell 的视图中。然后在 ForEach 中使用 Cell