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

# init(_:id:editActions:content:)

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

## Declaration

```swift
init<C, R>(_ data: Binding<C>, id: KeyPath<C.Element, ID>, editActions: EditActions<C>, @ContentBuilder content: @escaping (Binding<C.Element>) -> R) where Data == IndexedIdentifierCollection<C, ID>, Content == EditableCollectionContent<R, C>, C : MutableCollection, C : RandomAccessCollection, R : View, C.Index : Hashable
```

## Parameters

- `data`: The identified data that the doc://com.apple.SwiftUI/documentation/SwiftUI/ForEach instance uses to create views dynamically and can be edited by the user.
- `id`: The key path to the provided data’s identifier.
- `editActions`: The edit actions that are synthesized on data.
- `content`: The content builder that creates views 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. When placed inside a List the edit actions (like delete or move) can be automatically synthesized by specifying an appropriate EditActions. The following example shows a list of recipes whose elements can be deleted and reordered: List {     ForEach($recipes, editActions: [.delete, .move]) { $recipe in         RecipeCell($recipe)     } } Use deleteDisabled(_:) and moveDisabled(_:) to disable respectively delete or move actions on a per-row basis. The following example shows a list of recipes whose elements can be deleted only if they satisfy a condition: List {     ForEach($recipes, editActions: .delete) { $recipe in         RecipeCell($recipe)             .deleteDisabled(recipe.isFromMom)     } } Explicit DynamicViewContent.onDelete(perform:), DynamicViewContent.onMove(perform:), or View.swipeActions(edge:allowsFullSwipe:content:) modifiers will override any synthesized actions. Use this modifier if you need fine-grain control on how mutations are applied to the data driving the ForEach. For example, if you need to execute side effects or call into your existing model code.

## See Also

### Creating an editable collection

- [init(_:editActions:content:)](swiftui/foreach/init(_:editactions:content:).md)
