SwiftUI 使用ForEach 創(chuàng)建 view時(shí)報(bào)錯(cuò):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)
}
如果數(shù)組里面有重復(fù)的數(shù)據(jù)(例如上面的多個(gè)“1”)绳锅,就會(huì)報(bào) Fatal error: each layout item may only occur once: file SwiftUI, line 0,
貌似是布局重復(fù)的錯(cuò)誤初厚!
還是用的人不多,在網(wǎng)上找半天也沒(méi)有類似的問(wèn)題,谷歌也白搭祭埂!還的要自己慢慢摸索趴捅。
剛學(xué)習(xí)swiftUI,一個(gè)小問(wèn)題就要整半天卡辰,還得多多操練才行鞍濉!