Initializer

init(_:id:content:)

Creates an instance that generates Rotor content by combining, in order, individual Rotor content for each element in the data given to this ForEach.

Declaration 宣言

init(_ data: Data, id: KeyPath<Data.Element, ID>, content: @escaping (Data.Element) -> Content)
Available when Data conforms to RandomAccessCollection, ID conforms to Hashable, and Content conforms to AccessibilityRotorContent.

Parameters パラメータ

data

The data that the ForEach instance uses to create views dynamically.

id

The key path to the provided data’s identifier. 提供されたデータのもつ識別子へのキーパス。

content

The result builder that generates Rotor content for each data element.

Discussion 議論

It’s important that the id of a data element doesn’t change, unless SwiftUI considers the data element to have been replaced with a new data element that has a new identity. 重要なことは、あるデータ要素のidは変化しないことです、SwiftUIがそのデータ要素を新しい同一性を持つ新しいデータ要素と置き換えられたと見なさない限りは。

See Also 参照

Generating Rotor Content