<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextView/dragImageForSelection(with:origin:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextView(im)dragImageForSelectionWithEvent:origin:"
  },
  "title" : "dragImageForSelection(with:origin:)"
}
-->

# dragImageForSelection(with:origin:)

Returns an appropriate drag image for the drag initiated by the specified event.

```
func dragImageForSelection(with event: NSEvent, origin: NSPointPointer?) -> NSImage?
```

## Parameters

`event`

The event that initiated the drag session.

`origin`

On return, the lower-left point of the image in view coordinates.

## Return Value

An appropriate drag image for the drag initiated by `event`. May be `nil`, in which case a default icon will be used.

## Discussion

This method is used by [`dragSelection(with:offset:slideBack:)`](/documentation/AppKit/NSTextView/dragSelection(with:offset:slideBack:)). It can be called by others who need such an image, or can be overridden by subclasses to return a different image.

---

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)