Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Filter Services
Filter services (see System Services) provide a way to extend the types of data NSPasteboard
can provide to applications. In addition to the data types explicitly declared for a pasteboard, you can request the data in a type to which a filter service can convert any of the declared types. Files and NSData
objects can be converted as well using filters.
The NSPasteboard
class uses filter services when you invoke one of the following methods:
+ (NSArray *)typesFilterableTo:(NSString *)type |
+ (NSPasteboard *)pasteboardByFilteringFile:(NSString *)filename |
+ (NSPasteboard *)pasteboardByFilteringData:(NSData *)data ofType:(NSString *)type |
+ (NSPasteboard *)pasteboardByFilteringTypesInPasteboard:(NSPasteboard *)pboard |
The first returns an array of all the data types which can be converted to type. The last three return pasteboards with data that is filtered into all types derivable from the current types using available filter services. Filter services are not invoked, and the data converted, until data are requested from the pasteboard, so these methods are reasonably inexpensive.
Because filter services commonly translate data from unknown file formats into known formats, you need a way of dynamically specifying pasteboard types. The filter services and pasteboard facilities define types based on file extensions and HFS file types with these functions:
NSString *NSCreateFilenamePboardType(NSString *fileType) |
NSString *NSCreateFileContentsPboardType(NSString *fileType) |
NSString *NSGetFileType(NSString *pboardType) |
NSArray *NSGetFileTypes(NSArray *pboardTypes) |
NSString *NSFileTypeForHFSTypeCode(OSType hfsFileTypeCode) |
OSType NSHFSTypeCodeFromFileType(NSString *fileTypeString) |
The fileType argument is either a file extension, minus the period (for example, “eps
” or “tiff
”), or an HFS file type encoded with the NSFileTypeForHFSTypeCode
function (for example, “‘TEXT’
” or “‘MooV’
”). You create pasteboard type strings with the first two functions, and get file types (extensions or encoded HFS types) from pasteboard type strings with the second two functions. The last two functions convert between HFS file types (OSType
) and encoded HFS type strings.
Copyright © 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2009-01-20