Instance Method

collectionView(_:writeItemsAt:to:)

Places the data for the drag operation on the pasteboard.

Declaration

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

Parameters

collectionView

The collection view making the request.

indexPaths

The index paths of the items being dragged.

pasteboard

The pasteboard on which to place the drag data.

Return Value

true if the drag operation can continue or false if you want to refuse the drag.

Discussion

You must implement this method or the collectionView(_:pasteboardWriterForItemAt:) method to support drag operations. The collection view calls the collectionView(_:pasteboardWriterForItemAt:) method in preference to this one if both are implemented. If your app supports multi-image drag and drop, you must implement the collectionView(_:pasteboardWriterForItemAt:) method.

The collection view calls this method after it has determined that a drag should begin but before the drag operation has started. Your implementation of this method should do the following:

  1. Declare the pasteboard types you support using the declareTypes(_:owner:) method of the provided pasteboard object.

  2. Write data to the pasteboard for each type you declare.

  3. Return true from this method.

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, 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.