Contents

NSPasteboard

An object that transfers data to and from the pasteboard server.

Declaration

class NSPasteboard

Mentioned 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

Determining pasteboard access

Writing data

Reading data

Validating contents

Detecting patterns and metadata in pasteboard items

Preparing the pasteboard for content

Getting information about a pasteboard

Writing data (macOS 10.5 and earlier)

Reading data (macOS 10.5 and earlier)

Structures

Initializers

Default Implementations

See Also

Pasteboard