Instance Method

onDrop(of:isTargeted:perform:)

Defines the destination for a drag and drop operation with the same size and position as the view by handling dropped content with the specified closure.

Declaration

func onDrop(of supportedTypes: [String], isTargeted: Binding<Bool>?, perform action: @escaping ([NSItemProvider]) -> Bool) -> some View

Parameters

supportedTypes

The uniform type identifiers that describe the types of content this view can accept through drag and drop. If the drag and drop operation doesn’t contain any of the supported types, then this drop destination doesn’t activate and isTargeted doesn’t update.

isTargeted

A binding that updates when a drag and drop operation enters or exits the drop target area. The binding’s value is true when the cursor is inside the area, and false when the cursor is outside.

action

A closure that takes the dropped content and responds appropriately. The parameter to action contains the dropped items, with types specified by supportedTypes. Return true if the drop operation was successful; otherwise, return false.

Return Value

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

See Also

Supporting Drag and Drop in Views

func onDrag(() -> NSItemProvider) -> View

Activates the view as the source of a drag and drop operation.

func onDrop(of: [String], delegate: DropDelegate) -> View

Defines the destination of a drag and drop operation with the same size and position as the view using behavior controlled by the given delegate.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider], CGPoint) -> Bool) -> View

Defines the destination of a drag and drop operation with the same size and position as the view by handling dropped content and the drop location with the specified closure.

func itemProvider(Optional<() -> NSItemProvider?>) -> View

Provides a closure that vends the drag representation to be used for a particular data element.