init(_:id:content:)
Creates an instance that uniquely identifies and creates map content across updates based on the provided key path to the underlying data’s identifier.
Declaration
@MainActor init(_ data: Data, id: KeyPath<Data.Element, ID>, @MapContentBuilder content: @escaping (Data.Element) -> Content)Parameters
- data:
The data that the Foreach instance uses to create map content dynamically.
- id:
The key path to the provided data’s identifier.
- content:
The map content builder that creates map content dynamically.
Mentioned in
Discussion
It’s important that the id of a data element doesn’t change, unless the data element has been replaced with a new data element that has a new identity. If the id of a data element changes, then the map content generated from that data element will lose any current state and animations.