Drag and drop
Enable people to move or duplicate items by dragging them from one location to another.
Overview
Drag and drop offers people a convenient way to move content from one part of your app to another, from one app to another, or to reorder content using an intuitive dragging gesture. Support this feature in your app by adding view modifiers to potential source and destination views within your app’s interface.
[Image]
In your modifiers, provide or accept types that conform to the Transferable protocol, or that conform to NSItemProviderReading and/or NSItemProviderWriting. In Swift, prefer using transferable items.
For design guidance, see Drag and drop in the Human Interface Guidelines.
Topics
Essentials
Adopting drag and drop using SwiftUIMaking a view into a drag sourceReordering items in lists, stacks, grids, and custom layouts
Configuring drag-and-drop behavior
dragConfiguration(_:)DragConfigurationdropConfiguration(_:)DropConfigurationdragContainer(for:in:_:)dragContainer(for:itemID:in:_:)dragContainerSelection(_:containerNamespace:)
Moving items
Moving transferable items
draggable(_:)draggable(_:preview:)draggable(_:containerNamespace:_:)draggable(_:id:containerNamespace:_:)draggable(_:id:item:containerNamespace:)draggable(_:item:containerNamespace:)draggable(containerItemID:containerNamespace:)
Moving items using item providers
itemProvider(_:)onDrag(_:preview:)onDrag(_:)onDrop(of:isTargeted:perform:)onDrop(of:delegate:)DropDelegateDropProposalDropOperationDropInfo
Reordering items
Making a card game with drag, drop, and reordering in SwiftUIreorderable()reorderable(collectionID:)ReorderableSingleCollectionIdentifierreorderContainer(for:isEnabled:move:)reorderContainer(for:in:isEnabled:move:)reorderContainer(for:itemID:isEnabled:move:)reorderContainer(for:itemID:in:isEnabled:move:)reorderDestination(for:in:)reorderDestination(for:itemID:in:)ReorderDifference