<!--
{
  "availability" : [
    "macOS: 10.11.0 - 10.15.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:writeItemsAt:to:)-23ozm",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSCollectionViewDelegate(im)collectionView:writeItemsAtIndexPaths:toPasteboard:"
  },
  "title" : "collectionView(_:writeItemsAt:to:)"
}
-->

# collectionView(_:writeItemsAt:to:)

Places the data for the drag operation on the pasteboard.

```
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

<doc://com.apple.documentation/documentation/Swift/true> if the drag operation can continue or <doc://com.apple.documentation/documentation/Swift/false> if you want to refuse the drag.

## Discussion

You must implement this method or the [`collectionView(_:pasteboardWriterForItemAt:)`](/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:pasteboardWriterForItemAt:)-5eyyl) method to support drag operations. The collection view calls the [`collectionView(_:pasteboardWriterForItemAt:)`](/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:pasteboardWriterForItemAt:)-5eyyl) 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:)`](/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:pasteboardWriterForItemAt:)-5eyyl) 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:)`](/documentation/AppKit/NSPasteboard/declareTypes(_:owner:)) method of the provided `pasteboard` object.
2. Write data to the pasteboard for each type you declare.
3. Return <doc://com.apple.documentation/documentation/Swift/true> from this method.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)