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

# draggable(_:containerNamespace:_:)

Activates this view as the source of a drag and drop operation, allowing to provide optional identifiable payload and specify the namespace of the drag container this view belongs to.

## Declaration

```swift
nonisolated func draggable<Item>(_ itemType: Item.Type = Item.self, containerNamespace: Namespace.ID? = nil, _ item: @escaping () -> Item?) -> some View where Item : Transferable, Item : Identifiable, Item.ID : Sendable

```

## Parameters

- `itemType`: A type of the dragged item.
- `containerNamespace`: A namespace of the associated drag container.
- `item`: A closure that returns a single instance or a value conforming to doc://com.apple.documentation/documentation/CoreTransferable/Transferable that represents the draggable data from this view.

## Return Value

Return Value A view that activates this view as the source of a drag and drop operation, beginning with user gesture input.

## Discussion

Discussion Applying the draggable(_:containerNamespace_:) modifier adds the appropriate gestures for drag and drop to this view.    var fruits: [Fruit]

var body: some View {        ScrollView {            VStack {                ForEach(fruits) { fruit in                    FruitView(fruit)                        .draggable(fruit)                }            }        }    }

struct Fruit: Identifiable, Transferable { ... } If the draggable view is enclosed in a container, it participates in container drag-and-drop sessions:    var fruits: [Fruit]    var selectedFruits: [Fruit.ID]

var body: some View {        ScrollView {            VStack {                ForEach(fruits) { fruit in                    FruitView(fruit)                        .draggable(fruit)                }            }        }        .dragContainer(for: Fruit.self) { identifiers in            fruits(with: identifiers)        }        .dragContainerSelection(selectedFruits)    }

func fruits(with: [Fruit.ID]) -> [Fruit] { ... }    struct Fruit: Identifiable, Transferable { ... } When a drag operation begins, a rendering of this view is generated and used as the preview image.

## See Also

### Moving transferable items

- [draggable(_:)](swiftui/view/draggable(_:).md)
- [draggable(_:preview:)](swiftui/view/draggable(_:preview:).md)
- [draggable(_:id:containerNamespace:_:)](swiftui/view/draggable(_:id:containernamespace:_:).md)
- [draggable(_:id:item:containerNamespace:)](swiftui/view/draggable(_:id:item:containernamespace:).md)
- [draggable(_:item:containerNamespace:)](swiftui/view/draggable(_:item:containernamespace:).md)
- [draggable(containerItemID:containerNamespace:)](swiftui/view/draggable(containeritemid:containernamespace:).md)
