Contents

data(forType:)

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

Declaration

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

Reading data