---
title: "collectionView(_:writeItemsAt:to:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nscollectionviewdelegate/collectionview(_:writeitemsat:to:)-a1lk"
---

# collectionView(_:writeItemsAt:to:)

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

## Declaration

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

Return Value true to begin the drag, otherwise false.

## Discussion

Discussion To start the drag, you must first declare the pasteboard types that are supported by sending pasteboard a declareTypes(_:owner:) method. You then place the data for the items at the specified indexes on pasteboard, and return 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 true. You need to implement this method for your collection view to be a drag source.

## See Also

### Legacy Collection View Support

- [collectionView(_:canDragItemsAt:with:)](appkit/nscollectionviewdelegate/collectionview(_:candragitemsat:with:)-39rjh.md)
- [collectionView(_:pasteboardWriterForItemAt:)](appkit/nscollectionviewdelegate/collectionview(_:pasteboardwriterforitemat:)-7ldvs.md)
- [collectionView(_:namesOfPromisedFilesDroppedAtDestination:forDraggedItemsAt:)](appkit/nscollectionviewdelegate/collectionview(_:namesofpromisedfilesdroppedatdestination:fordraggeditemsat:)-wwec.md)
- [collectionView(_:draggingImageForItemsAt:with:offset:)](appkit/nscollectionviewdelegate/collectionview(_:draggingimageforitemsat:with:offset:)-4yvk5.md)
- [collectionView(_:draggingSession:willBeginAt:forItemsAt:)](appkit/nscollectionviewdelegate/collectionview(_:draggingsession:willbeginat:foritemsat:)-cpuq.md)
- [collectionView(_:validateDrop:proposedIndex:dropOperation:)](appkit/nscollectionviewdelegate/collectionview(_:validatedrop:proposedindex:dropoperation:).md)
- [collectionView(_:acceptDrop:index:dropOperation:)](appkit/nscollectionviewdelegate/collectionview(_:acceptdrop:index:dropoperation:).md)
