NSPasteboardReading Protocol Reference

Conforms to
Availability
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h
Companion guides
Related sample code

Overview

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.

Tasks

Initializing the Pasteboard

Reading From the Pasteboard

Class Methods

readableTypesForPasteboard:

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

+ (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSPasteboard.h

readingOptionsForType:pasteboard:

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

+ (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSPasteboard.h

Instance Methods

initWithPasteboardPropertyList:ofType:

Initializes an instance with a property list object and a type string.

- (id)initWithPasteboardPropertyList:(id)propertyList ofType:(NSString *)type
Parameters
propertyList

A property list containing data to initialize the receiver.

By default, the property list object is an instance of NSData. If you implement readingOptionsForType:pasteboard: and specify an option other than NSPasteboardReadingAsData, the propertyList may be any other property list object.

type

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

Return Value

An object initialized using the data in propertyList.

Special Considerations

This method is considered optional because, if readableTypesForPasteboard: returns just a single type, and that type uses the NSPasteboardReadingAsKeyedArchive reading option, then instances are initialized using initWithCoder: instead of this method.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSPasteboard.h

Constants

Pasteboard Reading Options

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

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

Reads data from the pasteboard as-is and returns it as an NSData object.

This is the default value.

Available in OS X v10.6 and later.

Declared in NSPasteboard.h.

NSPasteboardReadingAsString

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

Available in OS X v10.6 and later.

Declared in NSPasteboard.h.

NSPasteboardReadingAsPropertyList

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

Available in OS X v10.6 and later.

Declared in NSPasteboard.h.

NSPasteboardReadingAsKeyedArchive

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

Available in OS X v10.6 and later.

Declared in NSPasteboard.h.

Discussion

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