---
title: "data(forType:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nspasteboard/data(fortype:)"
---

# data(forType:)

Returns the data for the specified type from the first item in the receiver that contains the type.

## Declaration

```swift
func data(forType dataType: NSPasteboard.PasteboardType) -> Data?
```

## Parameters

- `dataType`: The type of data you want to read from the pasteboard. This value should be one of the types returned by doc://com.apple.appkit/documentation/AppKit/NSPasteboard/types or doc://com.apple.appkit/documentation/AppKit/NSPasteboard/availableType(from:).

## Return Value

Return Value A data object containing the data for the specified type from the first item in the receiver that contains the type, or nil if the contents of the pasteboard changed since they were last checked.

## Discussion

Discussion This method may also return nil if the pasteboard server cannot supply the data in time—for example, if the pasteboard’s owner is slow in responding to a pasteboard:provideDataForType: message and the interprocess communication times out. Discussion Errors other than a timeout raise an NSPasteboardCommunicationException. If nil is returned, the application should put up a panel informing the user that it was unable to carry out the paste operation. Note that sending types or availableType(from:) before invoking data(forType:) can help you determine whether a nil result from a reading method is due to something like a pasteboard timeout. Special Considerations For standard text data types such as string, RTF, and RTFD, the text data from each item is returned as one combined result separated by newlines.

## See Also

### Related Documentation

- [setData(_:forType:)](appkit/nspasteboard/setdata(_:fortype:).md)

### Reading data

- [readObjects(forClasses:options:)](appkit/nspasteboard/readobjects(forclasses:options:).md)
- [NSPasteboard.ReadingOptionKey](appkit/nspasteboard/readingoptionkey.md)
- [NSPasteboard.ReadingOptions](appkit/nspasteboard/readingoptions.md)
- [pasteboardItems](appkit/nspasteboard/pasteboarditems.md)
- [index(of:)](appkit/nspasteboard/index(of:).md)
- [propertyList(forType:)](appkit/nspasteboard/propertylist(fortype:).md)
- [string(forType:)](appkit/nspasteboard/string(fortype:).md)
