<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPasteboard",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPasteboard"
  },
  "title" : "NSPasteboard"
}
-->

# NSPasteboard

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

```
class NSPasteboard
```

## 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`](/documentation/AppKit/NSPasteboard) objects are an application’s sole interface to the server and to all pasteboard operations.

An [`NSPasteboard`](/documentation/AppKit/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`](/documentation/AppKit/NSPasteboardWriting) or [`NSPasteboardReading`](/documentation/AppKit/NSPasteboardReading) [Protocol](https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/Protocol.html#//apple_ref/doc/uid/TP40008195-CH45) 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:)`](/documentation/AppKit/NSPasteboard/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:

```objc
[pboard clearContents];
[pboard setData:data forType:type];
```

The general pasteboard, available by way of the [`general`](/documentation/AppKit/NSPasteboard/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

[`general`](/documentation/AppKit/NSPasteboard/general)

The shared pasteboard object to use for general content.

[`init(byFilteringData:ofType:)`](/documentation/AppKit/NSPasteboard/init(byFilteringData:ofType:))

Creates a new pasteboard object that supplies the specified data in as many types as possible based on the available filter services.

[`init(byFilteringFile:)`](/documentation/AppKit/NSPasteboard/init(byFilteringFile:))

Creates a new pasteboard object that supplies the specified file in as many types as possible based on the available filter services.

[`init(byFilteringTypesInPasteboard:)`](/documentation/AppKit/NSPasteboard/init(byFilteringTypesInPasteboard:))

Creates a new pasteboard object that supplies the specified pasteboard data in as many types as possible based on the available filter services.

[`init(name:)`](/documentation/AppKit/NSPasteboard/init(name:))

Returns the pasteboard with the specified name.

[`NSPasteboard.Name`](/documentation/AppKit/NSPasteboard/Name-swift.struct)

Constants that represent the standard pasteboard names.

[`withUniqueName()`](/documentation/AppKit/NSPasteboard/withUniqueName())

Creates and returns a new pasteboard with a name that is guaranteed to be unique with respect to other pasteboards in the system.

[`releaseGlobally()`](/documentation/AppKit/NSPasteboard/releaseGlobally())

Releases the receiver’s resources in the pasteboard server.

### Determining pasteboard access

[`accessBehavior`](/documentation/AppKit/NSPasteboard/accessBehavior-9k4t4)

The current pasteboard access behavior. The user can customize this behavior per-app in System Settings for any app that has triggered a pasteboard access alert in the past.

[`accessBehavior`](/documentation/AppKit/NSPasteboard/accessBehavior-86972)

The current pasteboard access behavior. The user can customize this behavior per-app in System Settings for any app that has triggered a pasteboard access alert in the past.

[`NSPasteboard.AccessBehavior`](/documentation/AppKit/NSPasteboard/AccessBehavior-swift.enum)

A value indicating pasteboard access behavior.

### Writing data

[`clearContents()`](/documentation/AppKit/NSPasteboard/clearContents())

Clears the existing contents of the pasteboard.

[`writeObjects(_:)`](/documentation/AppKit/NSPasteboard/writeObjects(_:))

Writes an array of objects to the receiver.

[`setData(_:forType:)`](/documentation/AppKit/NSPasteboard/setData(_:forType:))

Sets the data as the representation for the specified type for the first item on the receiver.

[`setPropertyList(_:forType:)`](/documentation/AppKit/NSPasteboard/setPropertyList(_:forType:))

Sets the given property list as the representation for the specified type for the first item on the receiver.

[`setString(_:forType:)`](/documentation/AppKit/NSPasteboard/setString(_:forType:))

Sets the given string as the representation for the specified type for the first item on the receiver.

[`NSPasteboard.PasteboardType`](/documentation/AppKit/NSPasteboard/PasteboardType)

The supported pasteboard types.

### Reading data

[`readObjects(forClasses:options:)`](/documentation/AppKit/NSPasteboard/readObjects(forClasses:options:))

Reads from the receiver objects that best match the specified array of classes.

[`NSPasteboard.ReadingOptionKey`](/documentation/AppKit/NSPasteboard/ReadingOptionKey)

Options for reading pasteboard data.

[`NSPasteboard.ReadingOptions`](/documentation/AppKit/NSPasteboard/ReadingOptions)

Options that specify how to interpret data on the pasteboard when initializing pasteboard data.

[`pasteboardItems`](/documentation/AppKit/NSPasteboard/pasteboardItems)

An array that contains all the items held by the pasteboard.

[`index(of:)`](/documentation/AppKit/NSPasteboard/index(of:))

Returns the index of the specified pasteboard item.

[`data(forType:)`](/documentation/AppKit/NSPasteboard/data(forType:))

Returns the data for the specified type from the first item in the receiver that contains the type.

[`propertyList(forType:)`](/documentation/AppKit/NSPasteboard/propertyList(forType:))

Returns the property list for the specified type from the first item in the receiver that contains the type.

[`string(forType:)`](/documentation/AppKit/NSPasteboard/string(forType:))

Returns a concatenation of the strings for the specified type from all the items in the receiver that contain the type.

### Validating contents

[`availableType(from:)`](/documentation/AppKit/NSPasteboard/availableType(from:))

Scans the specified types for a type that the receiver supports.

[`canReadItem(withDataConformingToTypes:)`](/documentation/AppKit/NSPasteboard/canReadItem(withDataConformingToTypes:))

Returns a Boolean value that indicates whether the receiver contains any items that conform to the specified UTIs.

[`canReadObject(forClasses:options:)`](/documentation/AppKit/NSPasteboard/canReadObject(forClasses:options:))

Returns a Boolean value that indicates whether the receiver contains any items that can be represented as an instance of any class in a given array.

[`types`](/documentation/AppKit/NSPasteboard/types)

An array of the receiver’s supported data types.

[`types(filterableTo:)`](/documentation/AppKit/NSPasteboard/types(filterableTo:))

Returns the data types that can be converted to the specified type using the available filter services.

### Detecting patterns and metadata in pasteboard items

[`detectedPatterns(for:)`](/documentation/AppKit/NSPasteboard/detectedPatterns(for:))

Determines whether the first pasteboard item matches the specified patterns, without notifying the person using the app.

[`detectPatternsForPatterns:completionHandler:`](/documentation/AppKit/NSPasteboard/detectPatternsForPatterns:completionHandler:)

Determines whether the first pasteboard item matches the specified patterns, without notifying the person using the app.

[`detectedValues(for:)`](/documentation/AppKit/NSPasteboard/detectedValues(for:))

Determines whether the first pasteboard item matches the specified patterns, reading the contents if it finds a match.

[`detectValuesForPatterns:completionHandler:`](/documentation/AppKit/NSPasteboard/detectValuesForPatterns:completionHandler:)

Determines whether the first pasteboard item matches the specified patterns, reading the contents if it finds a match.

[`NSPasteboard.DetectedValues`](/documentation/AppKit/NSPasteboard/DetectedValues)

A type that contains common types of data that the data detection system matches for a pasteboard.

[Pasteboard detection patterns](/documentation/AppKit/nspasteboard-detection-patterns)

Common types of data that the data detection system matches for a pasteboard.

[`detectedMetadata(for:)`](/documentation/AppKit/NSPasteboard/detectedMetadata(for:))

Determines available metadata from the specified metadata types for the first pasteboard item, without notifying the person using the app.

[`detectMetadataForTypes:completionHandler:`](/documentation/AppKit/NSPasteboard/detectMetadataForTypes:completionHandler:)

Determines available metadata from the specified metadata types for the first pasteboard item, without notifying the person using the app.

[`NSPasteboard.DetectedMetadata`](/documentation/AppKit/NSPasteboard/DetectedMetadata)

An object that contains common types of metadata that the data detection system matches for a pasteboard.

[Pasteboard detection metadata types](/documentation/AppKit/nspasteboard-detection-metadata-types)

Common types of metadata that the data detection system matches for a pasteboard.

### Preparing the pasteboard for content

[`prepareForNewContents(with:)`](/documentation/AppKit/NSPasteboard/prepareForNewContents(with:))

Prepares the pasteboard to receive new contents, removing the existing pasteboard contents.

[`NSPasteboard.ContentsOptions`](/documentation/AppKit/NSPasteboard/ContentsOptions)

Options for preparing the pasteboard.

### Getting information about a pasteboard

[`name`](/documentation/AppKit/NSPasteboard/name-swift.property)

The receiver’s name.

[`changeCount`](/documentation/AppKit/NSPasteboard/changeCount)

The receiver’s change count.

### Writing data (macOS 10.5 and earlier)

These methods all operate on what is conceptually the first item on the pasteboard. They accept UTIs and pboard type strings. In a future release they may take only UTIs.

[`declareTypes(_:owner:)`](/documentation/AppKit/NSPasteboard/declareTypes(_:owner:))

Prepares the receiver for a change in its contents by declaring the new types of data it will contain and a new owner.

[`addTypes(_:owner:)`](/documentation/AppKit/NSPasteboard/addTypes(_:owner:))

Adds promises for the specified types to the first pasteboard item.

[`writeFileContents(_:)`](/documentation/AppKit/NSPasteboard/writeFileContents(_:))

Writes the contents of the specified file to the pasteboard.

[`write(_:)`](/documentation/AppKit/NSPasteboard/write(_:))

Writes the serialized contents of the specified file wrapper to the pasteboard.

### Reading data (macOS 10.5 and earlier)

These methods all operate on what is conceptually the first item on the pasteboard. They accept UTIs and pboard type strings. In a future release they may take only UTIs.

[`readFileContentsType(_:toFile:)`](/documentation/AppKit/NSPasteboard/readFileContentsType(_:toFile:))

Reads data representing a file’s contents from the receiver and writes it to the specified file.

[`readFileWrapper()`](/documentation/AppKit/NSPasteboard/readFileWrapper())

Reads data representing a file’s contents from the receiver and returns it as a file wrapper.

### Structures

[`NSPasteboard.WritingOptions`](/documentation/AppKit/NSPasteboard/WritingOptions)

Type to specify options for writing to a pasteboard.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)