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

# writeSelection(to:types:)

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

## Declaration

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

Return Value true if the data for any single type was successfully written, false otherwise.

## Discussion

Discussion This method declares the data types on pboard and then invokes writeSelection(to:type:) or the delegate method 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.

## 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:type:)](appkit/nstextview/writeselection(to:type:).md)
- [validRequestor(forSendType:returnType:)](appkit/nstextview/validrequestor(forsendtype:returntype:).md)
