Instance Method

collectionView(_:validateDrop:proposedIndexPath:dropOperation:)

Validates whether a drop operation is possible at the specified location.

Declaration

optional func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndexPath proposedDropIndexPath: AutoreleasingUnsafeMutablePointer<NSIndexPath>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperation

Parameters

collectionView

The collection view asking you to validate the drop operation.

draggingInfo

The information about the drag operation.

proposedDropIndexPath

The index path at which the drop would occur. This parameter is passed by-reference and can be modified to change the proposed index path.

proposedDropOperation

The type of drop operation being proposed. This parameter is passed by-reference and can be modified to change the drop operation type.

Return Value

A value that indicates which dragging operation to perform. Return none to disallow a drop at the proposed location.

Discussion

Although implementation of this method is optional, you must implement it to support drops onto the associated collection view. You must also call the collection view’s registerForDraggedTypes(_:) method to register the types of drops it supports. If you do not perform both of these actions, the collection view does not accept drops.

When an interactive drag operation occurs, the collection view calls this method to determine whether the current mouse location is a valid place to drop the content. This method may be called many times during the course of the drag operation. Your implementation should look at the proposed location and return a constant that reflects how the drop would be handled.

While validating the drop location, you can suggest a better drop location by updating the values in the proposedDropIndexPath and proposedDropOperation parameters. For example, you might suggest dropping the content before the specified item instead of on it. The collection view sets the proposedDropOperation parameter to NSCollectionView.DropOperation.on when the mouse is closer to the middle of an item than to its edges; otherwise, it sets the parameter to NSCollectionView.DropOperation.before.

See Also

Drag and Drop Support

func collectionView(NSCollectionView, canDragItemsAt: Set<IndexPath>, with: NSEvent) -> Bool

Returns a Boolean indicating whether a drag operation involving the specified items can begin.

func collectionView(NSCollectionView, pasteboardWriterForItemAt: IndexPath) -> NSPasteboardWriting?

Provides the pasteboard writer for the item at the specified index path.

func collectionView(NSCollectionView, writeItemsAt: Set<IndexPath>, to: NSPasteboard) -> Bool

Places the data for the drag operation on the pasteboard.

Deprecated
func collectionView(NSCollectionView, namesOfPromisedFilesDroppedAtDestination: URL, forDraggedItemsAt: Set<IndexPath>) -> [String]

Returns the names of the promised files that you created for a drag operation.

Deprecated
func collectionView(NSCollectionView, updateDraggingItemsForDrag: NSDraggingInfo)

Asks your delegate to update the dragging items during a drag operation.