init(_:editActions:rowContent:)
Creates a list that computes its rows on demand from an underlying collection of identifiable data and enables editing the collection.
Declaration
@MainActor @preconcurrency init<Data, RowContent>(_ data: Binding<Data>, editActions: EditActions<Data>, @ViewBuilder rowContent: @escaping (Binding<Data.Element>) -> RowContent) where Content == ForEach<IndexedIdentifierCollection<Data, Data.Element.ID>, Data.Element.ID, EditableCollectionContent<RowContent, Data>>, Data : MutableCollection, Data : RandomAccessCollection, RowContent : View, Data.Element : Identifiable, Data.Index : HashableParameters
- data:
A collection of identifiable data for computing the list.
- editActions:
The edit actions that are synthesized on
data. - rowContent:
A view builder that creates the view for a single row of the list.
Discussion
The following example creates a list to display a collection of favorite foods allowing the user to delete or move elements from the collection.
List($foods, editActions: [.delete, .move]) { $food in
HStack {
Text(food.name)
Toggle("Favorite", isOn: $food.isFavorite)
}
}Use deleteDisabled(_:) and moveDisabled(_:) to disable respectively delete or move actions on a per-row basis.
Explicit DynamicViewContent.onDelete(perform:), DynamicViewContent.onMove(perform:), or View.swipeActions(edge:allowsFullSwipe:content:) modifiers will override any synthesized action