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

# collectionView(_:writeItemsAt:to:)

Invoked after it has been determined that a drag should begin, but before the drag has been started.

```
optional func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexes: IndexSet, to pasteboard: NSPasteboard) -> Bool
```

## Parameters

`collectionView`

The collection view that send the message.

`indexes`

The indexes of the items to write to the pasteboard.

`pasteboard`

The pasteboard containing the content from the dragged items.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> to begin the drag, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

To start the drag, you must first declare the pasteboard types that are supported by sending `pasteboard` a [`declareTypes(_:owner:)`](/documentation/AppKit/NSPasteboard/declareTypes(_:owner:)) method. You then place the data for the items at the specified indexes on `pasteboard`, and return <doc://com.apple.documentation/documentation/Swift/true> from the method.

The drag image and other drag related information will be set up and provided by the view once this call returns <doc://com.apple.documentation/documentation/Swift/true>.

You need to implement this method for your collection view to be a drag source.

---

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)