---
title: "writeSelection(to:type:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextview/writeselection(to:type:)"
---

# writeSelection(to:type:)

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

## Declaration

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

Return Value true if the data was successfully written, false otherwise.

## Discussion

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:). 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.

## See Also

### Managing the pasteboard

- [preferredPasteboardType(from:restrictedToTypesFrom:)](appkit/nstextview/preferredpasteboardtype(from:restrictedtotypesfrom:).md)
- [readSelection(from:)](appkit/nstextview/readselection(from:).md)
- [readSelection(from:type:)](appkit/nstextview/readselection(from:type:).md)
- [readablePasteboardTypes](appkit/nstextview/readablepasteboardtypes.md)
- [writablePasteboardTypes](appkit/nstextview/writablepasteboardtypes.md)
- [writeSelection(to:types:)](appkit/nstextview/writeselection(to:types:).md)
- [validRequestor(forSendType:returnType:)](appkit/nstextview/validrequestor(forsendtype:returntype:).md)
