<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:pasteboardWriterForItemAt:)-5eyyl",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSCollectionViewDelegate(im)collectionView:pasteboardWriterForItemAtIndexPath:"
  },
  "title" : "collectionView(_:pasteboardWriterForItemAt:)"
}
-->

# collectionView(_:pasteboardWriterForItemAt:)

Provides the pasteboard writer for the item at the specified index path.

```
@MainActor optional func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> (any NSPasteboardWriting)?
```

## Parameters

`collectionView`

The collection view making the request.

`indexPath`

The index path of the item requiring a pasteboard writer.

## Return Value

The pasteboard writer object to use for managing the item data. Return `nil` to prevent the collection view from dragging the item.

## Discussion

You must implement this method or the [`collectionView(_:writeItemsAt:to:)`](/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:writeItemsAt:to:)-23ozm) method to support drag operations. The collection view calls this method in preference over the [`collectionView(_:writeItemsAt:to:)`](/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:writeItemsAt:to:)-23ozm) method if both are implemented. If your app supports multi-image drag and drop, you must implement this method.

The collection view calls this method for each item involved in the drag operation after it has determined that a drag should begin but before the drag operation has started.  Your implementation of this method should create and return the pasteboard writer—an object conforming to the [`NSPasteboardWriting`](/documentation/AppKit/NSPasteboardWriting) protocol—to use for providing the item’s data. Using the object you provide, the collection view creates an [`NSDraggingItem`](/documentation/AppKit/NSDraggingItem) object for you and configures its [`draggingFrame`](/documentation/AppKit/NSDraggingItem/draggingFrame) and [`imageComponents`](/documentation/AppKit/NSDraggingItem/imageComponents) properties for you using information from the item at the specified index path.

If you implement this method, the collection view does not call the [`collectionView(_:draggingImageForItemsAt:with:offset:)`](/documentation/AppKit/NSCollectionViewDelegate/collectionView(_:draggingImageForItemsAt:with:offset:)-898js) of your delegate or the [`draggingImageForItems(at:with:offset:)`](/documentation/AppKit/NSCollectionView/draggingImageForItems(at:with:offset:)-7rc4k) method of [`NSCollectionView`](/documentation/AppKit/NSCollectionView).

---

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)