我正在遍歷 ForEach 并且一些陣列有 1 個索引,我想保持原樣。對于具有多個索引的陣列,我想通過管道將值分開,因此在每個回圈結束時,我想通過這樣做來查看是否存在更大的索引,$0 1但我不斷得到:Cannot convert value of type 'String' to expected condition type 'Bool'和`無法轉換'字串'型別的值到預期條件型別“Int”
ForEach(item.currency, id: \.self) {
Text(verbatim: $0)
.font(Font.custom("Avenir", size: 18))
.foregroundColor(Color("47B188"))
.padding(.leading, 18)
if (item.currency[$0 1]) {
Text("|")
}
}
uj5u.com熱心網友回復:
您需要迭代您的集合索引并檢查索引 1 是否小于集合 endIndex:
ForEach(item.currency.indices) {
Text(verbatim: item.currency[$0])
.font(Font.custom("Avenir", size: 18))
.foregroundColor(Color("47B188"))
.padding(.leading, 18)
if $0 1 < item.currency.endIndex {
Text("|")
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/368980.html
