Contents

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