NSPasteboard Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.0 and later. |
| Declared in | NSPasteboard.h |
| Companion guides | |
Overview
NSPasteboard objects transfer data to and from the pasteboard server. The server is shared by all running applications. It contains data that the user has cut or copied, as well as other data that one application wants to transfer to another. NSPasteboard objects are an application’s sole interface to the server and to all pasteboard operations.
An NSPasteboard object is also used to transfer data between applications and service providers listed in each application’s Services menu. The drag pasteboard (NSDragPboard) is used to transfer data that is being dragged by the user.
On OS X v10.6 and later, a pasteboard can contain multiple items. You can directly write or read any object that implements the NSPasteboardWriting Protocol Reference or NSPasteboardReading Protocol Reference protocol respectively. This allows you to write and read common items such as URLs, colors, images, strings, attributed strings, and sounds without an intermediary object. Your custom classes can also implement these protocols for use with the pasteboard.
The writing methods available on OS X v10.5 and earlier all operate on what is conceptually the first item on the pasteboard. They accept UTIs and pboard type strings. In a future release they may take only UTIs. On OS X v10.6 and later, the writing methods such as setData:forType: still provide a convenient means of writing to the first pasteboard item, without having to create the first pasteboard item. For example, instead of
[pboard clearContents]; |
NSPasteboardItem *item = [[[NSPasteboardItem alloc] init] autorelease]; |
[item setData:data forType:type]; |
[pboard writeObjects:[NSArray arrayWithObject:item]]; |
you can write:
[pboard clearContents]; |
[pboard setData:data forType:type]; |
In addition to being more compact, this is also a little more efficient—it avoids the need to create a separate pasteboard item and array.
Tasks
Creating and Releasing a Pasteboard
-
+ generalPasteboard -
+ pasteboardByFilteringData:ofType: -
+ pasteboardByFilteringFile: -
+ pasteboardByFilteringTypesInPasteboard: -
+ pasteboardWithName: -
+ pasteboardWithUniqueName -
– releaseGlobally
Writing Data
Reading Data
-
– readObjectsForClasses:options: -
– pasteboardItems -
– indexOfPasteboardItem: -
– dataForType: -
– propertyListForType: -
– stringForType:
Validating Contents
-
– availableTypeFromArray: -
– canReadItemWithDataConformingToTypes: -
– canReadObjectForClasses:options: -
– types -
+ typesFilterableTo:
Getting Information About a Pasteboard
Writing Data (OS X v10.5 and Earlier)
These methods all operate on what is conceptually the first item on the pasteboard. They accept UTIs and pboard type strings. In a future release they may take only UTIs.
Reading Data (OS X v10.5 and Earlier)
These methods all operate on what is conceptually the first item on the pasteboard. They accept UTIs and pboard type strings. In a future release they may take only UTIs.
Class Methods
generalPasteboard
Returns the general NSPasteboard object.
Return Value
The general pasteboard.
Discussion
Invokes pasteboardWithName: to obtain the pasteboard.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hpasteboardByFilteringData:ofType:
Creates and returns a new pasteboard with a unique name that supplies the specified data in as many types as possible given the available filter services.
Parameters
- data
The data to be placed on the pasteboard.
- type
The type of data in the data parameter.
Return Value
The new pasteboard object.
Discussion
The returned pasteboard also declares data of the supplied type.
No filter service is invoked until the data is actually requested, so invoking this method is reasonably inexpensive.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hpasteboardByFilteringFile:
Creates and returns a new pasteboard with a unique name that supplies the specified file data in as many types as possible given the available filter services.
Parameters
- filename
The filename to put on the pasteboard.
Return Value
The new pasteboard object.
Discussion
No filter service is invoked until the data is actually requested, so invoking this method is reasonably inexpensive.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hpasteboardByFilteringTypesInPasteboard:
Creates and returns a new pasteboard with a unique name that supplies the specified pasteboard data in as many types as possible given the available filter services.
Parameters
- pasteboard
The original pasteboard object.
Return Value
The new pasteboard object. This method returns the object in the pasteboard parameter if the pasteboard was returned by one of the pasteboardByFiltering... methods. This prevents a pasteboard from being expanded multiple times.
Discussion
This process can be thought of as expanding the pasteboard, because the new pasteboard generally contains more representations of the data than pasteboard.
This method only returns the original types and the types that can be created as a result of a single filter; the pasteboard does not have defined types that are the result of translation by multiple filters.
No filter service is invoked until the data is actually requested, so invoking this method is reasonably inexpensive.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hpasteboardWithName:
Returns the pasteboard with the specified name.
Parameters
- name
The name of the pasteboard. The names of standard pasteboards are given in “Pasteboard Names.”
Return Value
The pasteboard associated with the given name, or a new NSPasteboard object if the application does not yet have a pasteboard object for the specified name.
Discussion
Other names can be assigned to create private pasteboards for other purposes.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hpasteboardWithUniqueName
Creates and returns a new pasteboard with a name that is guaranteed to be unique with respect to other pasteboards on the computer.
Return Value
The new pasteboard object.
Discussion
This method is useful for applications that implement their own interprocess communication using pasteboards.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.htypesFilterableTo:
Returns the data types that can be converted to the specified type using the available filter services.
Parameters
- type
The target data type.
Return Value
An array of NSString objects containing the types that can be converted to the target data type.
Discussion
The array also contains the original type.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hInstance Methods
addTypes:owner:
Adds promises for the specified types to the first pasteboard item.
Parameters
- newTypes
An array of
NSStringobjects, each of which specifies a type of data that can be provided to the pasteboard.- newOwner
The object that provides the data for the specified types.
If the data for those types is provided immediately, the owner can be
nil. If the data for the added types will be provided lazily when requested from the pasteboard, an owner object must be provided that implements the -pasteboard:provideDataForType:method of theNSPasteboardOwnerinformal protocol.
Return Value
The new change count, or 0 if there was an error adding the types.
Discussion
This method adds promises for the specified types to the first pasteboard item.
You use this methods to declare additional types of data for the first pasteboard item in the receiver. You can also use it to replace existing types added by a previous declareTypes:owner: or addTypes:owner: message.
The newTypes parameter specifies the types of data you are promising to the pasteboard. The types should be ordered according to the preference of the source application, with the most preferred type coming first (typically, the richest representation). New types are added to the end of the list containing any existing types, if any.
If you specify a type that has already been declared, this method replaces the owner of that type with the value in newOwner. In addition, any data already already written to the pasteboard for that type is removed.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.havailableTypeFromArray:
Scans the specified types for a type that the receiver supports.
Parameters
- types
An array of
NSStringobjects specifying the pasteboard types your application supports, in preferred order.
Return Value
The first pasteboard type in types that is available on the pasteboard, or nil if the receiver does not contain any of the types in types.
Discussion
You use this method to determine the best representation available on the pasteboard. For example, if your application supports RTFD, RTF, and string data, then you might invoke the method as follows:
NSArray *supportedTypes = |
[NSArray arrayWithObjects: NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil]; |
NSString *bestType = [[NSPasteboard generalPasteboard] |
availableTypeFromArray:supportedTypes]; |
If the pasteboard contains RTF and string data, then bestType would contain NSRTFPboardType. If the pasteboard contains none of the types in supportedTypes, then bestType would be nil.
You must send a types or availableTypeFromArray: message before reading any data from an NSPasteboard object. If you need to see if a type in the returned array matches a type string you have stored locally, use the isEqualToString: method to perform the comparison.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hcanReadItemWithDataConformingToTypes:
Returns a Boolean value that indicates whether the receiver contains any items that conform to the specified UTIs.
Parameters
- types
An array of
NSStringobjects containing UTIs.
Return Value
YES if the receiver contains any items that conform to the UTIs specified in types, otherwise NO.
Availability
- Available in OS X v10.6 and later.
Declared In
NSPasteboard.hcanReadObjectForClasses:options:
Returns a Boolean value that indicates whether the receiver contains any items that can be represented as an instance of any class in a given array.
Parameters
- classArray
An array of class objects.
Classes in the array must conform to the
NSPasteboardReading Protocol Referenceprotocol.- options
A dictionary that specifies options to refine the search for pasteboard items, for example to restrict the search to file URLs with particular content types. For valid dictionary keys, see “Pasteboard Reading Options.”
Return Value
YES if the receiver contains any items that can be represented as an instance of a class specified in classArray, otherwise NO.
Availability
- Available in OS X v10.6 and later.
Declared In
NSPasteboard.hchangeCount
Returns the receiver’s change count.
Return Value
The change count of the receiver.
Discussion
The change count starts at zero when a client creates the receiver and becomes the first owner. The change count subsequently increments each time the pasteboard ownership changes.
The change count is also returned from clearContents and declareTypes:owner:. You can therefore record the change count at the time that you take ownership of the pasteboard and later compare it with the value returned from changeCount to determine whether you still have ownership.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hclearContents
Clears the existing contents of the pasteboard
Return Value
The change count of the receiver.
Discussion
Clears the existing contents of the pasteboard, preparing it for new contents. This is the first step in providing data on the pasteboard.
Availability
- Available in OS X v10.6 and later.
Declared In
NSPasteboard.hdataForType:
Returns the data for the specified type from the first item in the receiver that contains the type.
Parameters
- dataType
The type of data you want to read from the pasteboard. This value should be one of the types returned by
typesoravailableTypeFromArray:.
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.
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 a 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.
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.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hdeclareTypes:owner:
Prepares the receiver for a change in its contents by declaring the new types of data it will contain and a new owner.
Parameters
- newTypes
An array of
NSStringobjects that specify the types of data that may be added to the new pasteboard. The types should be ordered according to the preference of the source application, with the most preferred type coming first (typically, the richest representation).- newOwner
The object responsible for writing data to the pasteboard, or
nilif you provide data for all types immediately. If you specify a newOwner object, it must support all of the types declared in the newTypes parameter and must remain valid for as long as the data is promised on the pasteboard.
Return Value
The receiver's new change count.
Discussion
This method is the equivalent of invoking clearContents, implicitly writing the first pasteboard item, and then callingaddTypes:owner: to promise types for the first pasteboard item.
Special Considerations
In general, you should not use this method with writeObjects:, since writeObjects: will always write additional items to the pasteboard, and will not affect items already on the pasteboard, including the item implicitly created by this method.
Availability
- Available in OS X v10.0 and later.
See Also
-
– clearContents -
– addTypes:owner: -
– changeCount -
– pasteboard:provideDataForType:(NSPasteboardOwnerInformal Protocol)
Declared In
NSPasteboard.hindexOfPasteboardItem:
Returns the index of the specified pasteboard item.
Parameters
- pasteboardItem
A pasteboard item.
Return Value
The index of the specified pasteboard item. If pasteboardItem has not been added to any pasteboard, or is owned by another pasteboard, returns NSNotFound.
Discussion
An item’s index in the pasteboard is useful for a pasteboard item data provider that has promised data for multiple items, to be able to easily match the pasteboard item to an array of source data from which to derive the promised data.
Availability
- Available in OS X v10.6 and later.
Declared In
NSPasteboard.hname
Returns the receiver’s name.
Return Value
The name of the receiver.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hpasteboardItems
Returns all the items held by the receiver.
Return Value
Returns all the items held by the receiver, or nil if there is an error retrieving pasteboard items.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSPasteboard.hpropertyListForType:
Returns the property list for the specified type from the first item in the receiver that contains the type.
Parameters
- dataType
The pasteboard data type containing the property-list data.
Return Value
The property list for the specified type from the first item in the receiver that contains the type. This object consists of NSArray, NSData, NSDictionary, or NSString objects—or any combination thereof.
Discussion
This method invokes the dataForType: method.
Special Considerations
You must send types or availableTypeFromArray: before invoking propertyListForType:.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hreadFileContentsType:toFile:
Reads data representing a file’s contents from the receiver and writes it to the specified file.
Parameters
- type
The pasteboard data type to read. You should generally specify a value for this parameter. If you specify
nil, the filename extension (in combination with theNSCreateFileContentsPboardTypefunction) is used to determine the type.- filename
The file to receive the pasteboard data.
Return Value
The name of the file into which the data was actually written.
Discussion
Data of any file contents type should only be read using this method. If data matching the specified type is not found on the pasteboard, data of type NSFileContentsPboardType is requested.
Special Considerations
You must send an availableTypeFromArray: or types message before invoking readFileContentsType:toFile:.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hreadFileWrapper
Reads data representing a file’s contents from the receiver and returns it as a file wrapper.
Return Value
A file wrapper containing the pasteboard data, or nil if the receiver contained no data of type NSFileContentsPboardType.
Discussion
In OS X v10.5 and earlier, the file contents pboard type allowed you to synthesize a pboard type for a file's contents based on the file's extension. In OS X v10.5 and later, using the UTI of a file to represent its contents now replaces this functionality.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hreadObjectsForClasses:options:
Reads from the receiver objects that best match the specified array of classes.
Parameters
- classArray
An array of class objects.
The classes should appear in the array in the order the preferred order of representation. Classes in the array must conform to the
NSPasteboardReading Protocol Referenceprotocol.- options
A dictionary that specifies options to refine the search for pasteboard items, for example to restrict the search to file URLs with particular content types. For valid dictionary keys, see “Pasteboard Reading Options.”
Return Value
An array containing the best match (if any) for each of the items on the receiver that can be represented by a class specified in classArray. Returns nil if there is an error in retrieving the requested items from the pasteboard, or if no objects of the specified classes can be created.
Discussion
Classes in classArray must implement the NSPasteboardReading protocol. Cocoa classes that implement this protocol include NSImage, NSString, NSURL, NSColor, NSAttributedString, and NSPasteboardItem. For every item on the pasteboard, each class in the provided array will be queried for the types it can read using readableTypesForPasteboard:. An instance is created of the first class found in the provided array whose readable types match a conforming type contained in that pasteboard item. Any instances that could be created from pasteboard item data is returned to the caller. Additional options, such as restricting the search to file URLs with particular content types, can be specified with an options dictionary.
Only objects of the requested classes are returned. You can always ensure to receive one object per item on the pasteboard by including the NSPasteboardItem class in the array of classes.
Consider the following example: there are five items on the pasteboard, two contain TIFF data, two contain RTF data, one contains a private data type. The following table shows what objects you get back in the returned array for different classes in classArray
Classes in classArray | Returned objects |
|---|---|
| Two |
| Two |
| Two |
| Two |
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSPasteboard.hreleaseGlobally
Releases the receiver’s resources in the pasteboard server.
Discussion
After this method is invoked, no other application can use the receiver.
Special Considerations
A temporary, privately named pasteboard can be released this way when it is no longer needed, but a standard pasteboard should never be released globally.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hsetData:forType:
Sets the given data as the representation for the specified type for the first item on the receiver.
Parameters
- data
The data to write to the pasteboard.
- dataType
The type of data in the data parameter. The type must have been declared by a previous
declareTypes:owner:message.
Return Value
YES if the data was written successfully, otherwise NO if ownership of the pasteboard has changed. Any other error raises an NSPasteboardCommunicationException.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hsetPropertyList:forType:
Sets the given property list as the representation for the specified type for the first item on the receiver.
Parameters
- propertyList
The property list data to write to the pasteboard.
- dataType
The type of property-list data in the propertyList parameter. The type must have been declared by a previous
declareTypes:owner:message.
Return Value
YES if the data was written successfully, otherwise NO if ownership of the pasteboard has changed. Any other error raises an NSPasteboardCommunicationException.
Discussion
This method invokes setData:forType: with a serialized property list parameter.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hsetString:forType:
Sets the given string as the representation for the specified type for the first item on the receiver.
Parameters
- string
The string to write to the pasteboard.
- dataType
The type of string data. The type must have been declared by a previous
declareTypes:owner:message.
Return Value
YES if the data was written successfully, otherwise NO if ownership of the pasteboard has changed. Any other error raises an NSPasteboardCommunicationException.
Discussion
This method invokes setData:forType: to perform the write.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hstringForType:
Returns a concatenation of the strings for the specified type from all the items in the receiver that contain the type.
Parameters
- dataType
The pasteboard data type to read.
Return Value
A concatenation of the strings for the specified type from all the items in the receiver that contain the type, or nil if none of the items contain strings of the specified type.
Discussion
This method invokes dataForType: to obtain the string. If the string cannot be obtained, stringForType: returns nil. See dataForType: for a description of what will cause nil to be returned.
In OS X v10.6 and later, if the receiver contains multiple items that can provide string, RTF, or RTFD data, the text data from each item is returned as a combined result separated by newlines.
Special Considerations
You must send types or availableTypeFromArray: before invoking stringForType:.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.htypes
Returns an array of the receiver’s supported data types.
Return Value
An array of NSString objects containing the union of the types of data declared for all the pasteboard items on the receiver. The returned types are listed in the order they were declared.
Discussion
You must send a types or availableTypeFromArray: message before reading any data from an NSPasteboard object. If you need to see if a type in the returned array matches a type string you have stored locally, use the isEqualToString: method to perform the comparison.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hwriteFileContents:
Writes the contents of the specified file to the pasteboard.
Parameters
- filename
The name of the file to write to the pasteboard.
Return Value
YES if the data was successfully written, otherwise NO.
Discussion
Writes the contents of the file filename to the receiver and declares the data to be of type NSFileContentsPboardType and also of a type appropriate for the file’s extension (as returned by the NSCreateFileContentsPboardType function when passed the files extension), if it has one.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPasteboard.hwriteFileWrapper:
Writes the serialized contents of the specified file wrapper to the pasteboard.
Parameters
- wrapper
The file wrapper to write to the pasteboard.
Return Value
YES if the data was successfully written, otherwise NO.
Discussion
Writes the serialized contents of the file wrapper wrapper to the receiver and declares the data to be of type NSFileContentsPboardType and also of a type appropriate for the file’s extension (as returned by the NSCreateFileContentsPboardType function when passed the files extension), if it has one. If wrapper does not have a preferred filename, this method raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPasteboard.hwriteObjects:
Writes an array of objects to the receiver.
Parameters
- objects
An array of objects that implement the
NSPasteboardWriting Protocol Referenceprotocol (including instances ofNSPasteboardItem).
Return Value
YES if the array was successfully added, otherwise NO.
Availability
- Available in OS X v10.6 and later.
Declared In
NSPasteboard.hConstants
Pasteboard Names
The NSPasteboard class defines the following named pasteboards.
NSString *NSGeneralPboard; NSString *NSFontPboard; NSString *NSRulerPboard; NSString *NSFindPboard; NSString *NSDragPboard;
Constants
NSGeneralPboardThe pasteboard that’s used for ordinary cut, copy, and paste operations.
This pasteboard holds the contents of the last selection that’s been cut or copied.
Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSFontPboardThe pasteboard that holds font and character information and supports Copy Font and Paste Font commands that may be implemented in a text editor.
Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSRulerPboardThe pasteboard that holds information about paragraph formats in support of the Copy Ruler and Paste Ruler commands that may be implemented in a text editor.
Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSFindPboardThe pasteboard that holds information about the current state of the active application’s find panel.
This information permits users to enter a search string into the find panel, then switch to another application to conduct another search.
Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSDragPboardThe pasteboard that stores data to be moved as the result of a drag operation.
For additional information on working with the drag pasteboard, see Drag and Drop Programming Topics.
Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.
Declared In
AppKit/NSPasteboard.hTypes for Standard Data (OS X v10.6 and later)
The NSPasteboard class uses the following constants to define UTIs for common pasteboard data types.
NSString *const NSPasteboardTypeString; NSString *const NSPasteboardTypePDF; NSString *const NSPasteboardTypeTIFF; NSString *const NSPasteboardTypePNG; NSString *const NSPasteboardTypeRTF; NSString *const NSPasteboardTypeRTFD; NSString *const NSPasteboardTypeHTML; NSString *const NSPasteboardTypeTabularText; NSString *const NSPasteboardTypeFont; NSString *const NSPasteboardTypeRuler; NSString *const NSPasteboardTypeColor; NSString *const NSPasteboardTypeSound; NSString *const NSPasteboardTypeMultipleTextSelection; NSString *const NSPasteboardTypeFindPanelSearchOptions;
Constants
NSPasteboardTypeStringString data.
Important: Files passed by path cannot be accessed by sandboxed applications. For this reason, you should avoid putting paths on the pasteboard using the
NSPasteboardTypeStringtype in OS X v10.7 and later. Instead, use anNSURL, a bookmark, or a filename pasteboard type.Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypePDFPDF data.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeTIFFTag Image File Format (TIFF) data.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypePNGPNG image data.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeRTFRich Text Format (RTF) data.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeRTFDRTFD formatted file contents.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeHTMLHTML data.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeTabularTextAn
NSStringobject containing tab-separated fields of text.Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeFontFont and character information.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeRulerParagraph formatting information.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeColorColor data (an
NSColorobject).Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeSoundSound data (an
NSSoundobject).Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeMultipleTextSelectionMultiple text selection.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeFindPanelSearchOptionsType for the Find panel metadata property list.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.
Types for Standard Data (OS X v10.5 and earlier)
The NSPasteboard class uses the following common pasteboard data types.
NSString *NSStringPboardType; NSString *NSFilenamesPboardType; NSString *NSPostScriptPboardType; NSString *NSTIFFPboardType; NSString *NSRTFPboardType; NSString *NSTabularTextPboardType; NSString *NSFontPboardType; NSString *NSRulerPboardType; NSString *NSFileContentsPboardType; NSString *NSColorPboardType; NSString *NSRTFDPboardType; NSString *NSHTMLPboardType; NSString *NSPICTPboardType; NSString *NSURLPboardType; NSString *NSPDFPboardType; NSString *NSVCardPboardType; NSString *NSFilesPromisePboardType; NSString *NSMultipleTextSelectionPboardType;
Constants
NSColorPboardTypeNSColordata.On OS X v10.6 and later, use
NSPasteboardTypeColor(and you read and write colors directly to and from the pasteboard).Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSFileContentsPboardTypeA representation of a file’s contents.
The file contents pboard type allowed you to synthesize a pboard type for a file's contents based on the file's extension.
On OS X v10.6 and later, you should use the UTI of a file to represent its contents instead.
Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSFilenamesPboardTypeAn array of
NSStringobjects designating one or more filenames.On OS X v10.6 and later, use
writeObjects:to write file URLs to the pasteboard.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSFontPboardTypeFont and character information.
On OS X v10.6 and later, use
NSPasteboardTypeFontinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSHTMLPboardTypeHTML (which an
NSTextViewobject can read from, but not write to).On OS X v10.6 and later, use
NSPasteboardTypeHTMLinstead.Available in OS X v10.1 and later.
Declared in
NSPasteboard.h.NSPDFPboardTypePDF data.
On OS X v10.6 and later, use
NSPasteboardTypePDFinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSPICTPboardTypeQuickDraw picture data.
The PICT format was formally deprecated in OS X v10.4 along with QuickDraw. You should not be explicitly providing or looking for PICT data on the pasteboard.
To aid in this deprecation, if PICT is the only image type on the pasteboard, as is sometimes the case when copying images from 32-bit Carbon applications, a translated image type will be automatically reported and provided by
NSPasteboard. The translated type is added to the types array ahead of PICT so that the deprecated PICT format is not the preferred format. In addition, when an application provides image data toNSPasteboard, the Carbon Pasteboard Manager will automatically make a PICT translation available to 32-bit Carbon applications.Although
NSPICTPboardType, and its UTI equivalentkUTTypePICT, will appear in a pasteboard's type array retrieved from the existingNSPasteboardAPI, it may cease to be reported in future releases.Available in OS X v10.0 and later.
Deprecated in OS X v10.6.
Declared in
NSPasteboard.h.NSPostScriptPboardTypeEncapsulated PostScript (EPS) code.
On OS X v10.6 and later, use
@"com.adobe.encapsulated-postscript"instead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSRulerPboardTypeParagraph formatting information.
On OS X v10.6 and later, use
NSPasteboardTypeRulerinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSRTFPboardTypeRich Text Format (RTF) data.
On OS X v10.6 and later, use
NSPasteboardTypeRTFinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSRTFDPboardTypeRTFD formatted file contents.
On OS X v10.6 and later, use
NSPasteboardTypeRTFDinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSStringPboardTypeNSStringdata. (Deprecated. On OS X v10.6 and later, useNSPasteboardTypeStringinstead. Also, files passed by path cannot be accessed by sandboxed applications. For this reason, you should avoid putting paths on the pasteboard using theNSStringPboardTypetype in OS X v10.7 and later. Instead, use anNSURL, a bookmark, or a filename pasteboard type.)Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSTabularTextPboardTypeAn
NSStringobject containing tab-separated fields of text.On OS X v10.6 and later, use
NSPasteboardTypeTabularTextinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSTIFFPboardTypeTag Image File Format (TIFF) data.
On OS X v10.6 and later, use
NSPasteboardTypeTIFFinstead.Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSURLPboardTypeNSURLdata for one file or resource.On OS X v10.6 and later, use
writeObjects:to write URLs directly to the pasteboard instead.On OS X v10.5 and earlier: to write an URL to a pasteboard you use
writeToPasteboard:(NSURL); to get an URL from a pasteboard you useURLFromPasteboard:(NSURL).Available in OS X v10.0 and later.
Declared in
NSPasteboard.h.NSVCardPboardTypeVCard data.
On OS X v10.6 and later, use
(NSString *)kUTTypeVCardinstead.Available in OS X v10.2 and later.
Declared in
NSPasteboard.h.NSFilesPromisePboardTypePromised files.
On OS X v10.6 and later, use
(NSString *)kPasteboardTypeFileURLPromiseinstead.For information on promised files, see Dragging Files in Drag and Drop Programming Topics.
Available in OS X v10.2 and later.
Declared in
NSPasteboard.h.NSInkTextPboardTypeInk text data.
On OS X v10.6 and later, use
(NSString *)kUTTypeInkTextinstead.For information on ink text objects, see Using Ink Services in Your Application.
Available in OS X v10.4 and later.
Declared in
NSPasteboard.h.NSMultipleTextSelectionPboardTypeMultiple text selection.
On OS X v10.6 and later, use
NSPasteboardTypeMultipleTextSelectioninstead.Available in OS X v10.5 and later.
Declared in
NSPasteboard.h.NSPasteboardTypeTextFinderOptionsType for the Find panel metadata property list..
Available in OS X v10.7 and later.
Declared in
NSPasteboard.h.
Discussion
See also NSSoundPboardType (NSSound).
Version Notes
Pboard types will be deprecated in a future release. On OS X 10.6 and later you should replace any use of pboard types with UTIs, including the constants described in “Types for Standard Data (OS X v10.6 and later).”
Pasteboard Reading Options
These options can be used for both the readObjectsForClasses:options: and canReadObjectForClasses:options: methods, unless otherwise specified. The currently available options allow for customization of how URLS are read from the pasteboard.
NSString *NSPasteboardURLReadingFileURLsOnlyKey; NSString *NSPasteboardURLReadingContentsConformToTypesKey;
Constants
NSPasteboardURLReadingFileURLsOnlyKeyOption for reading URLs to restrict the results to file URLs only.
The value for this key is an
NSNumberobject with a boolean value.Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.NSPasteboardURLReadingContentsConformToTypesKeyOption for reading URLs to restrict the results to URLs with contents that conform to any of the provided UTI types.
If the content type of a URL cannot be determined, it will not be considered to match. The value for this key is an array of UTI type strings.
Available in OS X v10.6 and later.
Declared in
NSPasteboard.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-05-14)