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

# writeSelection(to:type:)

Writes the current selection to the specified pasteboard using the given type.

```
func writeSelection(to pboard: NSPasteboard, type: NSPasteboard.PasteboardType) -> Bool
```

## Parameters

`pboard`

The pasteboard to write to.

`type`

The type of data to write.

## Return Value

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

## Discussion

The complete set of data types being written to `pboard` should be declared before invoking this method.

This method should be invoked only from [`writeSelection(to:types:)`](/documentation/AppKit/NSTextView/writeSelection(to:types:)). You can override this method to add support for writing new types of data to the pasteboard. You should invoke `super`’s implementation of the method to handle any types of data your overridden version does not.

---

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)