본문 바로가기
SwiftUI

[SwiftUI] `ForEach(_:content:)` should only be used for *constant* data.

by 고고 2021. 11. 25.
=== AttributeGraph: cycle detected through attribute 697368 ===

ForEach<Range<Int>, Int, ModifiedContent<MessageRow, _PaddingLayout>> count (8) != its initial count (7). `ForEach(_:content:)` should only be used for *constant* data. Instead conform data to `Identifiable` or use `ForEach(_:id:content:)` and provide an explicit `id`!

 

안녕하세요 ◠‿◠ 고고입니다.

갑자기 저 위의 문구가 한 20개쯤은 떠서 당황했는데 읽어보면 ForEach를 할 때 idenfiable을 상속하는 데이터를 쓰거나 id를 넣어달란 뜻이었습니다.

따라서 다음과 같이 고쳤습니다.

// Before
ForEach(0..<channel.allMsgs.count) { index in
	Text("")
}
   
// After
ForEach(0..<channel.allMsgs.count, id: \.self) { index in
	Text("")
}

댓글