<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ForEach/init(_:id:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI7ForEachV08_MapKit_aB0AD0E7ContentR0_rlE_2id7contentACyxq_q0_Gx_s7KeyPathCy7ElementQzq_Gq0_ALctcfc::OverloadGroup"
  },
  "title" : "init(_:id:content:)"
}
-->

# 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.

```
@MainActor init(_ data: Data, id: KeyPath<Data.Element, ID>, @MapContentBuilder content: @escaping (Data.Element) -> Content)
```

## Parameters

`data`

The data that the [`ForEach`](/documentation/SwiftUI/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.

## 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)