Returns the data for the specified type from the first item in the receiver that contains the type.
SDK
- macOS 10.0+
Framework
- App
Kit
Declaration
- (NSData *)dataForType:(NSPasteboard Type)dataType;
Parameters
dataType
The type of data you want to read from the pasteboard. This value should be one of the types returned by
types
oravailable
.Type From Array:
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.
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:
message and the interprocess communication times out.
Discussion
Errors other than a timeout raise an NSPasteboard
.
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 available
before invoking data
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.