<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/draggable(_:id:containerNamespace:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE9draggable_2id18containerNamespace_Qrqd__m_s7KeyPathCyqd__qd_0_GAA0G0V2IDVSgqd__Sgyct16CoreTransferable0L0Rd__SHRd_0_s8SendableRd_0_r0_lF"
  },
  "title" : "draggable(_:id:containerNamespace:_:)"
}
-->

# draggable(_:id:containerNamespace:_:)

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

```
nonisolated func draggable<Item, ItemID>(_ itemType: Item.Type = Item.self, id: KeyPath<Item, ItemID>, containerNamespace: Namespace.ID? = nil, _ payload: @escaping () -> Item?) -> some View where Item : Transferable, ItemID : Hashable, ItemID : Sendable
```

## Parameters

`itemType`

A type of the dragged item.

`id`

An key path of the identifier of an item.

`containerNamespace`

A namespace of the associated drag container.

`payload`

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

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

## Discussion

Applying the `draggable(_:id:containerNamespace:_:)` modifier adds
the appropriate gestures for drag and drop to this view.
When a drag operation begins, a rendering of
this view is generated and used as the preview image.

```
var fruits: [Fruit]

var body: some View {
    ScrollView {
        VStack {
            ForEach(fruits) { fruit in
                FruitView(fruit)
                    .draggable(Fruit.self, id: \.dragID) {
                        fruit.supportsDrag ? fruit : nil
                    }
            }
        }
    }
}

struct Fruit: Transferable {
    var supportsDrag: Bool
    var dragID: UUID
}
```

If the draggable view is enclosed in a container, it participates
in container drag-and-drop sessions:

```
var fruits: [Fruit]
var selectedFruits: [UUID]

var body: some View {
    ScrollView {
        VStack {
            ForEach(fruits) { fruit in
                FruitView(fruit)
                    .draggable(Fruit.self, id: \.dragID) {
                        fruit.supportsDrag ? fruit : nil
                    }
            }
        }
    }
    .dragContainer(for: Fruit.self) { identifiers in
        fruits(with: identifiers)
    }
    .dragContainerSelection(selectedFruits)
}

func fruits(with: [UUID]) -> [Fruit] { ... }
```

---

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)