---
title: "dragContainerSelection(_:containerNamespace:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/dragcontainerselection(_:containernamespace:)"
---

# dragContainerSelection(_:containerNamespace:)

Provides multiple item selection support for drag containers.

## Declaration

```swift
nonisolated func dragContainerSelection<ItemID>(_ selection: @autoclosure @escaping () -> Array<ItemID>, containerNamespace: Namespace.ID? = nil) -> some View where ItemID : Hashable, ItemID : Sendable

```

## Parameters

- `selection`: A closure that provides identifiers of selected items.
- `containerNamespace`: An optional namespace of the drag container.

## Discussion

Discussion A drag container finds the nearest enclosing dragContainerSelection(_:containerNamespace:) with the same item identifier type and same namespace, if specified. Drag container uses the provided selected item identifiers to determine what the drag payload should be. If the dragged view is associated with a selected identifier, the payload should contain all the selected items. If the dragged view is not selected, the payload should not contain the whole selection, just the dragged item. With dragContainerSelection(_:containerNamespace:), you get fine-grained control over what items are included in the drag payload.     struct FruitContainer: View {          @State private var fruits: [Fruit]          @State private var selection: [Fruit.ID]

var body: some View {              VStack {                  ForEach(fruits) { fruit in                      FruitView(fruit)                          .draggable(containerItemID: fruit.id)                   }               }              .dragContainer(for: Fruit.self) { ids in                  fruits(with: ids)              }              .dragContainerSelection(selection)          }

func fruits(with ids: [Fruit.ID]) -> [Fruit] { ... }

struct Fruit: Transferable, Identifiable {            let id: String            ...        }

struct FruitView: View {            init(_ fruit: Fruit) { ... }        }    }

## See Also

### Configuring drag-and-drop behavior

- [dragConfiguration(_:)](swiftui/view/dragconfiguration(_:).md)
- [DragConfiguration](swiftui/dragconfiguration.md)
- [dropConfiguration(_:)](swiftui/view/dropconfiguration(_:).md)
- [DropConfiguration](swiftui/dropconfiguration.md)
- [dragContainer(for:in:_:)](swiftui/view/dragcontainer(for:in:_:).md)
- [dragContainer(for:itemID:in:_:)](swiftui/view/dragcontainer(for:itemid:in:_:).md)
