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

# writeSelection(to:types:)

Writes the current selection to the specified pasteboard under each given type.

```
func writeSelection(to pboard: NSPasteboard, types: [NSPasteboard.PasteboardType]) -> Bool
```

## Parameters

`pboard`

The pasteboard to write to.

`types`

An array of strings describing the types of data to write.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the data for any single type was successfully written, <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## Discussion

This method declares the data types on `pboard` and then invokes [`writeSelection(to:type:)`](/documentation/AppKit/NSTextView/writeSelection(to:type:)) or the delegate method [`textView(_:write:at:to:type:)`](/documentation/AppKit/NSTextViewDelegate/textView(_:write:at:to:type:)) for each type in the `types` array.

You should not need to override this method. You might need to invoke this method if you are implementing a new type of pasteboard to handle services other than copy/paste or dragging.

---

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)