NSPasteboard objects transfer data to and from the pasteboard server. The 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.
- macOS 10.10+
NSPasteboard object is also used to transfer data between apps 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.
A pasteboard can contain multiple items. You can directly write or read any object that implements the
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:
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.