collectionView(_:acceptDrop:indexPath:dropOperation:)
Incorporates the dropped content into the collection view.
Declaration
@MainActor optional func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: any NSDraggingInfo, indexPath: IndexPath, dropOperation: NSCollectionView.DropOperation) -> BoolParameters
- collectionView:
The collection view receiving the dropped content.
- draggingInfo:
The information about the drag operation.
- indexPath:
The index path at which the drop occurred. Use this location as the insertion point for the content.
- dropOperation:
The type of drop operation to perform.
Return Value
true if the drop operation should be accepted or false if it should be rejected.
Discussion
The collection view calls this method when the user releases the mouse button while it is over a valid drop target. This method is called after the collectionView(_:validateDrop:proposedIndexPath:dropOperation:) method validates that dropping the content at the specified location is possible. You must implement this method to accept the dropped content and incorporate it into the collection view.
In your implementation, use the information in the draggingInfo parameter to retrieve the data, update your data source object, and insert the appropriate items into the collection view. The dropped data is stored in the draggingPasteboard property of the dragging information object.
If the animatesToDestination property of the dragging information is true, update the image and frame for each dragged item to its new location in the collection view. You can enumerate the list of dragged items using the enumerateDraggingItems(options:for:classes:searchOptions:using:) method of the dragging information object.
See Also
Drag and Drop Support
Supporting Collection View Drag and Drop Through File PromisescollectionView(_:canDragItemsAt:with:)collectionView(_:pasteboardWriterForItemAt:)collectionView(_:writeItemsAt:to:)collectionView(_:namesOfPromisedFilesDroppedAtDestination:forDraggedItemsAt:)collectionView(_:draggingImageForItemsAt:with:offset:)collectionView(_:draggingSession:willBeginAt:forItemsAt:)collectionView(_:draggingSession:endedAt:dragOperation:)collectionView(_:updateDraggingItemsForDrag:)collectionView(_:validateDrop:proposedIndexPath:dropOperation:)