Contents

reorderable(collectionID:)

Enables reordering views from this content within and between sections in the scope of a reorderable container modifier.

Declaration

nonisolated func reorderable(collectionID: some Hashable & Sendable) -> some DynamicViewContent<Self.Data>

Parameters

  • collectionID:

    The identifier that represents this collection. Its value is used in the destination value when reordering.

Mentioned in

Discussion

Declare this modifier on DynamicViewContent within a reorderable container to allow people to reorder the items in the content using a system drag gesture. A reorderable container is a list, stack, grid, or custom layout that you define with the reorderContainer(for:in:isEnabled:move:) modifier.

Use this modifier when you have multiple collections in the container. Provide a collection identifier to uniquely identify the collection. If your container has a single collection, provide ReorderableSingleCollectionIdentifier as the identifier, or use reorderable() instead.

This example shows a sectioned list of reminders:

struct ContentView: View {
    @State private var model = ReminderModel()

    var body: some View {
        List {
            ForEach(model.sections) { section in
                Section(section.name) {
                    ForEach(section.reminders) { reminder in
                        ReminderView(reminder)
                    }
                    .reorderable(collectionID: section.id)
                }
            }
        }
        .reorderContainer(
            for: Reminder.self, in: ReminderModel.Section.ID.self
        ) { difference in
            model.apply(difference: difference)
        }
    }
}

See Also

Reordering items