Instance Method

onDrag(_:)

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

Declaration

func onDrag(_ data: @escaping () -> NSItemProvider) -> some View

Parameters

data

A closure that returns a single NSItemProvider 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 onDrag(_:) 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.

See Also

Supporting Drag and Drop in Views

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

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

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

Defines the destination for a drag and drop operation with the same size and position as this view, handling dropped content and the drop location with the given closure.

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

Defines the destination for a drag and drop operation, using the same size and position as this view, handling dropped content with the given closure.