NSPasteboardReading Protocol Reference
| Conforms to | |
| Availability | Available in OS X v10.6 and later. |
| Declared in | NSPasteboard.h |
| Companion guides | |
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.
Class Methods
readableTypesForPasteboard:
Returns an array of UTI strings of data types the receiver can read from the pasteboard and be initialized from.
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.hreadingOptionsForType:pasteboard:
Returns options for reading data of a specified type from a given 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.hInstance Methods
initWithPasteboardPropertyList:ofType:
Initializes an instance with a property list object and a type string.
Parameters
- propertyList
A property list containing data to initialize the receiver.
By default, the property list object is an instance of
NSData. If you implementreadingOptionsForType:pasteboard:and specify an option other thanNSPasteboardReadingAsData, 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.hConstants
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
NSPasteboardReadingAsDataReads data from the pasteboard as-is and returns it as an
NSDataobject.This is the default value.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardReadingAsStringReads data from the pasteboard and converts it to an
NSStringobject.Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardReadingAsPropertyListReads data from the pasteboard and un-serializes it as a property list.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardReadingAsKeyedArchiveReads 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.
© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-03-08)