<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ForEach/init(_:editActions:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI7ForEachVAAE_11editActions7contentACyAA27IndexedIdentifierCollectionVyqd__q_Gq_AA08EditableJ7ContentVyqd_0_qd__GGAA7BindingVyqd__G_AA04EditF0Vyqd__Gqd_0_ANy7ElementSTQyd__GctcAHRszASST_2IDQYd__Rs_AKRs0_SMRd__SkRd__AA4ViewRd_0_s12IdentifiableATRQSH5IndexSlRpd__r0_lufc"
  },
  "title" : "init(_:editActions:content:)"
}
-->

# init(_:editActions:content:)

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

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

## Parameters

`data`

The identified data that the [`ForEach`](/documentation/SwiftUI/ForEach) instance uses to
create views dynamically and can be edited by the user.

`editActions`

The edit actions that are synthesized on `data`.

`content`

The content builder that creates views dynamically.

## 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(_:)`](/documentation/SwiftUI/View/deleteDisabled(_:)) and [`moveDisabled(_:)`](/documentation/SwiftUI/View/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.

---

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)