Instance Method

dataForType:

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

Declaration

- (NSData *)dataForType:(NSPasteboardType)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 or availableTypeFromArray:.

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: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 availableTypeFromArray: before invoking dataForType: 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

Reading Data

- readObjectsForClasses:options:

Reads from the receiver objects that best match the specified array of classes.

NSPasteboardReadingOptionKey

These options can be used for both the readObjectsForClasses:options: and canReadObjectForClasses:options: methods, unless otherwise specified. The currently available options allow for customization of how URLS are read from the pasteboard.

pasteboardItems

An array that contains all the items held by the receiver or nil if there is an error retrieving pasteboard items.

- indexOfPasteboardItem:

Returns the index of the specified pasteboard item.

- propertyListForType:

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

- stringForType:

Returns a concatenation of the strings for the specified type from all the items in the receiver that contain the type.