dropDestination

Defines the destination of a drag and drop operation that provides a drop operation proposal and handles the dropped content with a closure that you specify.

View ModifieriOS 26.0+macOS 26.0+visionOS 26.0+dropDestination(for:isEnabled:action:) in SwiftUI

Declaration

React
compose().dropDestination<T>({
  isEnabled?: boolean,
  action: (items: T[], session: SwiftUI.DropSession) => void,
})
Swift
nonisolated func dropDestination<T>(
    for type: T.Type = T.self,
    isEnabled: Bool = true,
    action: @escaping ([T], DropSession) -> Void
) -> some View
where T : Transferable

Parameters

  • options.isEnabledboolean

    The Boolean value indicating if the view accepts drop interactions.

  • options.action*(items: T[], session: SwiftUI.DropSession) => void

    A closure that takes the dropped content and responds appropriately. The first parameter to action contains the dropped items. The second parameter contains the drop session description.

Return value

A view that provides a drop destination for a drop operation of the specified type.

Discussion

The dropped content can be provided as binary data, file URLs, or file promises.

The drop destination is the same size and position as this view.

@State private var isDropTargeted = false
@Binding var isDropEnabled: Bool

var body: some View {
    Color.pink
        .frame(width: 400, height: 400)
        .dropDestination(
            for: String.self, isEnabled: isDropEnabled
        ) { receivedTitles, session in
            animateDrop(at: session.location)
            process(titles: receivedTitles)
        }
}

func process(titles: [String]) { ... }
func animateDrop(at: CGPoint) { ... }

See also

More in Drag and drop.