Mac Developer Library

Developer

NSPasteboardReading Protocol Reference

Options
Deployment Target:

On This Page
Language:

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.

Inheritance


Not Applicable

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.6 and later.
  • Returns an array of UTI strings of data types the receiver can read from the pasteboard and be initialized from.

    Declaration

    Swift

    class func readableTypesForPasteboard(_ pasteboard: NSPasteboard!) -> [AnyObject]!

    Objective-C

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    optional class func readingOptionsForType(_ type: String!, pasteboard pasteboard: NSPasteboard!) -> NSPasteboardReadingOptions

    Objective-C

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    struct NSPasteboardReadingOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var AsData: NSPasteboardReadingOptions { get } static var AsString: NSPasteboardReadingOptions { get } static var AsPropertyList: NSPasteboardReadingOptions { get } static var AsKeyedArchive: NSPasteboardReadingOptions { get } }

    Objective-C

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

    Constants

    • AsData

      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.

    • AsString

      NSPasteboardReadingAsString

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

      Available in OS X v10.6 and later.

    • AsPropertyList

      NSPasteboardReadingAsPropertyList

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

      Available in OS X v10.6 and later.

    • AsKeyedArchive

      NSPasteboardReadingAsKeyedArchive

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

      Available in OS X v10.6 and later.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.