<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIPasteboard/setData(_:forPasteboardType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIPasteboard(im)setData:forPasteboardType:"
  },
  "title" : "setData(_:forPasteboardType:)"
}
-->

# setData(_:forPasteboardType:)

Puts data on the pasteboard for the specified representation type.

```
func setData(_ data: Data, forPasteboardType pasteboardType: String)
```

## Parameters

`data`

The data object to be written to the pasteboard.

`pasteboardType`

A string identifying the representation type of the pasteboard item. This is typically a UTI.

## Discussion

Use this method to put raw data on the pasteboard. For example, you could archive a graph of model objects and pass the resulting <doc://com.apple.documentation/documentation/Foundation/NSData> object to a related app via a pasteboard using a custom pasteboard type. (To put objects—such as <doc://com.apple.documentation/documentation/Foundation/NSString>, <doc://com.apple.documentation/documentation/Foundation/NSArray>, <doc://com.apple.documentation/documentation/Foundation/NSDictionary>, <doc://com.apple.documentation/documentation/Foundation/NSDate>, <doc://com.apple.documentation/documentation/Foundation/NSNumber>, [`UIImage`](/documentation/UIKit/UIImage), or <doc://com.apple.documentation/documentation/Foundation/NSURL> objects—on the pasteboard, use the [`setValue(_:forPasteboardType:)`](/documentation/UIKit/UIPasteboard/setValue(_:forPasteboardType:)) method.) This method writes data for the first item in the pasteboard. Calling this method replaces any items currently in the 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)