Pasteboard

A pasteboard is a secure and standardized mechanism for the exchange of data within or between applications. Many operations depend on the pasteboard, notable copy-cut-paste. On OS X, drag-and-drop operations and application services also depend upon the pasteboard. But you can also use pasteboards in other situations where sharing data between applications is desirable.

A pasteboard in iOS is represented by an instance of the UIPasteboard class; the equivalent class in OS X is NSPasteboard. Pasteboard objects access a shared repository where a writer object and a reader object meet to exchange data. The writer, also known as the pasteboard owner, deposits data on a pasteboard instance and moves on. The reader accesses the pasteboard, asynchronously, and copies the data into its address space.

Pasteboards can be public or private to one or more applications. Public pasteboards are system provided and are available to all applications. All pasteboards, public and private, must have a unique name. Both platforms have general-purpose pasteboards and pasteboards used in search operations. In iOS, these pasteboards are named UIPasteboardNameGeneral and UIPasteboardNameFind; in OS X, they are named NSGeneralPboard and NSFindPboard. OS X has additional named system pasteboards for rulers, fonts, and drag-and-drop operations. An application on either platform typically uses one of the system pasteboards, but may create a private pasteboard under a unique name; for example, it might create a private pasteboard to share data with a “sibling” application that was created by the same software vendor.

A Pasteboard Holds Multiple Items in Multiple Representations

A pasteboard item is a piece of data placed onto a pasteboard. A pasteboard can hold a single item, such as an image file or a document, or it can hold multiple items. Methods of the pasteboard classes (and, on OS X, the NSPasteboardItem class) enable you to write and read single or multiple pasteboard items either as property-list objects or as binary data.

Art/items_representation.jpg

To facilitate sharing between applications with different capabilities, a pasteboard item can include multiple representations of the same data. For example, a rich-text editor might provide RTFD, RTF, and plain-text representations of the data it writes as a pasteboard item. Each representation of an item is identified by a different Uniform Type Identifier (UTI).

The Persistence of Pasteboards

In OS X, a pasteboard server running in the background gives persistence to data put on pasteboards. When the application depositing the data terminates, the data remains available for any interested reader. The pasteboard server maintains an arbitrary number of individual pasteboards to distinguish among several concurrent data transfers.

In iOS, public (system) pasteboards are persistent, but by default private (application) pasteboards are not. These private pasteboards do not continue to exist when the application that creates them quits. However, you can mark application pasteboards as persistent.

Prerequisite Articles

    (None)

Definitive Discussion

    Copy, Cut, and Paste Operations

Sample Code Projects

  • CopyPasteTile