<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPasteboard/data(forType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPasteboard(im)dataForType:"
  },
  "title" : "data(forType:)"
}
-->

# data(forType:)

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

```
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 [`types`](/documentation/AppKit/NSPasteboard/types) or [`availableType(from:)`](/documentation/AppKit/NSPasteboard/availableType(from:)).

## 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

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 <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/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`](/documentation/AppKit/NSPasteboard/types) or [`availableType(from:)`](/documentation/AppKit/NSPasteboard/availableType(from:)) before invoking [`data(forType:)`](/documentation/AppKit/NSPasteboard/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

[`setData(_:forType:)`](/documentation/AppKit/NSPasteboard/setData(_:forType:))

Sets the data as the representation for the specified type for the first item on the receiver.



---

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)