swift - 无法转换“ClosedRange”类型的值'到预期的参数类型'范围'
问题描述
我有这个代码:
VStack {
ForEach(0...2) { i in
HStack {
ForEach(0...2) { j in
Text("test")
}
}
}
}
这给了我Cannot convert value of type 'ClosedRange<Int>' to expected argument type 'Range<Int>'
两个 ForEach 语句的错误
我已经看到有关此错误的线程,并且对范围事物的工作原理有所了解,但实际上并非如此。我想知道如何解决这个错误。
解决方案
可以使用ClosedRange
但使用不同的ForEach
构造函数,提供id
,如
VStack {
ForEach(0...2, id: \.self) { i in
HStack {
ForEach(0...2, id: \.self) { j in
Text("test")
}
}
}
}
推荐阅读
- vue.js - Quasar 浏览器扩展无法构建,开发工作正常
- php - PHP - 解析 HTML,选择标签,在所选标签内插入另一个 HTML 字符串
- javascript - 有没有办法将动作绑定到不是 Angular 上某个键绑定的每个击键?
- html - 为什么我的页面中的 col-md-6 显示全宽?
- c++ - 删除链表 C++ 中的特定节点
- sql - Apex Oracle calendar When Select list value is null show all and when Select value is not null show filtered
- xpath - 如何单击柏树中跨度类下的链接
- r - 我在尝试连接 R Markdown 中的数据但在非 Markdown 文件中较早工作时遇到错误
- javascript - minmax/1fr 背后的数学原理是什么?
- javascript - 如何将跨度文本转换为输入表单