SwiftUI 踩坑记——ForEach 创建 view报错:Fatal error: each layout item may only occur once: file SwiftUI, l...

SwiftUI 使用ForEach 创建 view时报错:Fatal error: each layout item may only occur once: file SwiftUI, line 0
代码片段如下:

let array = ["1","1","2","3","4","5","6"]
ForEach(array, id: \.self) { item in
  Text(item)
 }

如果数组里面有重复的数据(例如上面的多个“1”),就会报 Fatal error: each layout item may only occur once: file SwiftUI, line 0,
貌似是布局重复的错误!
还是用的人不多,在网上找半天也没有类似的问题,谷歌也白搭!还的要自己慢慢摸索。
刚学习swiftUI,一个小问题就要整半天,还得多多操练才行啊!

你可能感兴趣的:(SwiftUI 踩坑记——ForEach 创建 view报错:Fatal error: each layout item may only occur once: file SwiftUI, l...)