NSPasteboard
An object that transfers data to and from the pasteboard server.
Declaration
class NSPasteboardMentioned in
Overview
The pasteboard server is shared by all running apps. 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 apps and service providers listed in each application’s Services menu. The drag pasteboard is used to transfer data that is being dragged by the user.
A pasteboard can contain multiple items. You can directly write or read any object that implements the NSPasteboardWriting or NSPasteboardReading 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.
Writing methods such as setData(_:forType:) provide a convenient means of writing to the first pasteboard item, without having to create the first pasteboard item. You can use code like this, for example:
[pboard clearContents];
[pboard setData:data forType:type];The general pasteboard, available by way of the general class method, automatically participates with the Universal Clipboard feature in macOS 10.12 and later and in iOS 10.0 and later. There is no macOS API for interacting with this feature.
Topics
Creating and releasing a pasteboard
generalinit(byFilteringData:ofType:)init(byFilteringFile:)init(byFilteringTypesInPasteboard:)init(name:)NSPasteboard.NamewithUniqueName()releaseGlobally()
Determining pasteboard access
Writing data
clearContents()writeObjects(_:)setData(_:forType:)setPropertyList(_:forType:)setString(_:forType:)NSPasteboard.PasteboardType
Reading data
readObjects(forClasses:options:)NSPasteboard.ReadingOptionKeyNSPasteboard.ReadingOptionspasteboardItemsindex(of:)data(forType:)propertyList(forType:)string(forType:)
Validating contents
availableType(from:)canReadItem(withDataConformingToTypes:)canReadObject(forClasses:options:)typestypes(filterableTo:)
Detecting patterns and metadata in pasteboard items
detectedPatterns(for:)detectedValues(for:)NSPasteboard.DetectedValuesPasteboard detection patternsdetectedMetadata(for:)NSPasteboard.DetectedMetadataPasteboard detection metadata types