[英]Cannot convert value of type 'ClosedRange<Int>' to expected argument type 'Range<Int>'
I have this code:我有这个代码:
VStack {
ForEach(0...2) { i in
HStack {
ForEach(0...2) { j in
Text("test")
}
}
}
}
This give me error Cannot convert value of type 'ClosedRange<Int>' to expected argument type 'Range<Int>'
on both ForEach statements这给了我错误
Cannot convert value of type 'ClosedRange<Int>' to expected argument type 'Range<Int>'
I've seen threads on this error and kind of get it a bit on how the range thing works but not really.我已经看到有关此错误的线程,并且对范围事物的工作原理有所了解,但实际上并非如此。 I'm wondering how to fix this error.
我想知道如何解决这个错误。
It is possible to use ClosedRange
but with different ForEach
constructor, providing id
, like可以使用
ClosedRange
但具有不同的ForEach
构造函数,提供id
,例如
VStack {
ForEach(0...2, id: \.self) { i in
HStack {
ForEach(0...2, id: \.self) { j in
Text("test")
}
}
}
}
You can use ..<
instead of ...
for range to be of type Range<Index>
instead of ClosedRange<Index>
您可以使用
..<
而不是...
使范围的类型为Range<Index>
而不是ClosedRange<Index>
VStack {
ForEach(0..<2) { i in
HStack {
ForEach(0..<2) { j in
Text("test")
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.