Mac Developer Library

Developer

NSPasteboardReading Protocol Reference

Options
Deployment Target:

On This Page

NSPasteboardReading

The NSPasteboardReading protocol specifies the interface for initializing an object from a pasteboard.

The Cocoa framework classes NSString, NSAttributedString, NSURL, NSColor, NSSound, NSImage, and NSPasteboardItem implement this protocol. You can make your custom class conform to this protocol so that you can read instances from a pasteboard using the readObjectsForClasses:options: method of NSPasteboard.

  • Returns an array of UTI strings of data types the receiver can read from the pasteboard and be initialized from.

    Declaration

    + (NSArray *)readableTypesForPasteboard:(NSPasteboard *)pasteboard

    Parameters

    pasteboard

    A pasteboard.

    You can use the pasteboard argument to provide different types based on the pasteboard name, should you need to do so.

    Return Value

    An array of UTI strings of data types instances of the receiver can read from the pasteboard and be initialized from.

    Discussion

    By default, the data for a type is provided to initWithPasteboardPropertyList:ofType: as an instance of NSData. If you implement readingOptionsForType:pasteboard: and specify a different option, the NSData object for a type can be converted to an NSString object or any other property list object.

    Special Considerations

    Do not perform other pasteboard operations in the method implementation.

  • Returns options for reading data of a specified type from a given pasteboard.

    Declaration

    + (NSPasteboardReadingOptions)readingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pasteboard

    Parameters

    type

    A UTI supported by instances of the receiver for reading (one of the types returned by readableTypesForPasteboard:).

    pasteboard

    A pasteboard.

    You can use the pasteboard argument to provide return different based on the pasteboard name, should you need to do so.

    Return Value

    Options for reading data of type from pasteboard. For a list of valid values, see Pasteboard Reading Options.

    Special Considerations

    Do not perform other pasteboard operations in this method implementation.

  • Options to specify how data on the pasteboard should be interpreted to initialize an object in initWithPasteboardPropertyList:ofType:.

    Declaration

    enum { NSPasteboardReadingAsData = 0, NSPasteboardReadingAsString = 1 << 0, NSPasteboardReadingAsPropertyList = 1 << 1, NSPasteboardReadingAsKeyedArchive = 1 << 2 }; typedef NSUInteger NSPasteboardReadingOptions;

    Constants

    • NSPasteboardReadingAsData

      This is the default value.

    • NSPasteboardReadingAsString

      Reads data from the pasteboard and converts it to an NSString object.

    • NSPasteboardReadingAsPropertyList

      Reads data from the pasteboard and un-serializes it as a property list.

    • NSPasteboardReadingAsKeyedArchive

      Reads data from the pasteboard and uses initWithCoder: to initialize the object.

    Discussion

    You can specify only one option from this list. If you do not specify an option, the default NSPasteboardReadingAsData is used.