내용

<aside> 🔥

</aside>

2.png

1.png

해결?

struct TopEpisode: Identifiable {
    let id = UUID()
    let thumbnail: String
    let title: String
    let date: String
    let time: String
}

// ...

// Int 값을 식별자로 사용하게 된다.
ForEach(0..<topShows.count, id: \\.self) { index in
    TopShowsItem(topShow: topShows[index], index: index + 1)
}

// Int 타입의 해당 인덱스 값을 식별자로 사용하게 된다.
ForEach(topShows.indices, id: \\.self) { index in
    TopShowsItem(topShow: topShows[index], index: index + 1)
}

그렇다면.. 어째서..?

Why?

id 파라미터가 없는 이니셜라이저를 사용했던 경우 Range<Int> 로 여겨 일정하지 않은 범위일 수 있는 경고를 보여주지만

스크린샷 2022-04-19 오전 3.19.19.png

id 파라미터가 있는 이니셜라이저를 사용하니 data 파라미터는 Range<Int> 가 아닌 Data 로 여기기 때문입니다.

스크린샷 2022-04-19 오전 3.19.08.png

위의 방법보다 더 나은 방법은!