【发布时间】:2020-01-05 08:28:43
【问题描述】:
我知道之前有人问过涉及此错误的问题,但我检查了它们,但它们并没有解决我的问题。
我有一个名为 data 的字典,其中包含 event 对象。我正在将 rowData 与 data 中的所有事件进行比较,以查看它们是否匹配。搜索完成后,我不想创建或更新视图,我只想更新数据字段。
struct addToMyMoves {
var rowData: row
//rowData is passed into the struct from an outside View
func addToMoves() {
ForEach(data){ event in
//Error: Unable to infer complex closure return type; add explicit type to disambiguate
if (event.name == rowData.name) {
event.favorite.toggle()
}
}
}
}
当我尝试按照类似帖子中的建议将 if 语句放入 Group {} 中时,如下所示,我收到“无法推断通用参数'内容'”错误
struct addToMyMoves {
var rowData: row
//rowData is passed into the struct from an outside View
func addToMoves() {
ForEach(data){ event in
//Error: Unable to infer complex closure return type; add explicit type to disambiguate
Group {
if (event.name == rowData.name) {
event.favorite.toggle()
}
}
}
}
}
【问题讨论】: