---
title: "init(_:content:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/foreach/init(_:content:)"
---

# init(_:content:)

Creates an instance that uniquely identifies and creates map content across updates based on the identity of the underlying data.

## Declaration

```swift
@MainActor init(_ data: Data, @MapContentBuilder content: @escaping (Data.Element) -> Content) where ID == Data.Element.ID, Data.Element : Identifiable
```

## Parameters

- `data`: The identified data that the doc://com.apple.SwiftUI/documentation/SwiftUI/ForEach instance uses to create map content dynamically.
- `content`: The map content builder that creates map content dynamically.

## Discussion

Discussion It’s important that the id of a data element doesn’t change unless you replace the data element with a new data element that has a new identity. If the id of a data element changes, the content view generated from that data element loses any current state and animations.

## See Also

### Creating a collection

- [init(_:)](swiftui/foreach/init(_:).md)
- [init(_:id:content:)](swiftui/foreach/init(_:id:content:).md)
- [init(sections:content:)](swiftui/foreach/init(sections:content:).md)
- [init(subviews:content:)](swiftui/foreach/init(subviews:content:).md)
