Instance Method インスタンスメソッド

onPasteCommand(of:validator:perform:)

Adds an action to perform in response to the system’s Paste command with items that you validate. あなたが妥当と認める項目をもつシステム「ペースト」コマンドに答えて実行するあるアクションを加えます。

Declaration 宣言

func onPasteCommand<Payload>(of supportedContentTypes: [UTType], validator: @escaping ([NSItemProvider]) -> Payload?, perform payloadAction: @escaping (Payload) -> Void) -> some View

Return Value 戻り値

A view that triggers action when the system paste command is invoked, validating the paste command with validator. あるビュー、それはactionをシステムのペーストコマンドが発動される時に引き起こします、ペーストコマンドをvalidatorで検証しています。

Parameters パラメータ

supportedContentTypes

The uniform type identifiers that describe the types of content this view can accept through a paste action. If the pasteboard 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 pasteboard with the types you specify in the supportedContentTypes. 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. コマンドを検証するハンドラ。このハンドラは、あなたがsupportedContentTypesにおいて指定する型をもつペーストボードから項目を受け取ります。このハンドラを使って、項目それらが有効であるかどうかを決定してください、そしてそれらをactionクロージャのために前処理してください。あなたがnilを代わりに返すならば、ペーストコマンドは引き起こされません。

payloadAction

The action to perform when the paste command triggers. ペーストコマンドが引き起こされる時に実行するアクション。

Discussion 議論

Pass an array of uniform type identifiers to the supportedContentTypes parameter. Place the higher priority types closer to the beginning of the array. The pasteboard items that the validator closure receives have the most preferred type out of all the types the source supports. ユニホーム型識別子それらからなるある配列をsupportedContentTypesパラメータに渡してください。より高い優先度の型を配列の始まりに置いてください。validatorクロージャが受け取るペーストボード項目は、ソースがサポートする全ての型の中で最も優先される型を持ちます。

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. 例えば、あなたのアプリがプレーンテキストとリッチテキストを取り扱える、しかしあなたがリッチテキストのほうを好むならば、リッチテキスト型をその配列において最初に置いてください。ペーストアクションが発生する時にリッチテキストが利用可能ならば、validatorクロージャはそのリッチテキストを手渡します。

See Also 参照

Copy and Paste