<!--
{
  "availability" : [
    "macOS: 10.15.0 - 27.2.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onPasteCommand(of:validator:perform:)-964k1",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE14onPasteCommand2of9validator7performQrSaySSG_qd__SgSaySo14NSItemProviderCGcyqd__ctlF"
  },
  "title" : "onPasteCommand(of:validator:perform:)"
}
-->

# onPasteCommand(of:validator:perform:)

Adds an action to perform in response to the system’s
Paste command with items that you validate.

```
nonisolated func onPasteCommand<Payload>(of supportedTypes: [String], validator: @escaping ([NSItemProvider]) -> Payload?, perform payloadAction: @escaping (Payload) -> Void) -> some View
```

## Parameters

`supportedTypes`

The uniform type identifiers that describe the
types of content this view can accept through a paste action.
If the Clipboard doesn’t contain any of the supported types, the
Paste command doesn’t trigger.

`validator`

A handler that validates the command. This handler
receives items from the Clipboard with the types you specify in the
`supportedTypes` parameter. Use this handler to decide whether
the items are valid and preprocess them for the `action` closure.
If you return `nil` instead, the Paste command doesn’t trigger.

`payloadAction`

The action to perform when the Paste command triggers.

## Return Value

A view that triggers `action` when the system Paste command
is invoked, validating the Paste command with `validator`.

## Discussion

Pass an array of uniform type identifiers to the `supportedTypes`
parameter. Place the higher priority types closer to the beginning of the
array. The Clipboard items that the `validator` closure receives have the
most preferred type out of all the types the source supports.

For example, if your app can handle plain text and rich text, but you
prefer rich text, place the rich text type first in the array. If rich
text is available when the paste action occurs, the `validator` closure
passes that rich text along.

---

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)