<!--
{
  "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(_:item:containerNamespace:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE9draggable_4item18containerNamespaceQrqd__m_qd__SgyXAAA0G0V2IDVSgt16CoreTransferable0J0Rd__s12IdentifiableRd__s8SendableAJsAOPRpd__lF"
  },
  "title" : "draggable(_:item:containerNamespace:)"
}
-->

# draggable(_:item: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.

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

## Parameters

`itemType`

A type of the dragged item.

`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.

`containerNamespace`

A namespace of the associated drag container.

## 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(_:_: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.

If the view is enclosed in a `dragContainer(for:in:_)`, the
view becomes its draggable element, and the item’s identifier
is used as drag payload identifier.

```
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)
    }
}

func fruits(with: [Fruit.ID]) -> [Fruit] { ... }
struct Fruit: Identifiable, Transferable { ... }
```

---

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)