cuttable
Specifies an action that moves items to the Clipboard in response to the system's Cut command.
Declaration
compose().cuttable<T>({
action: T[],
})nonisolated func cuttable<T>(
for payloadType: T.Type = T.self,
action: @escaping () -> [T]
) -> some View
where T : TransferableParameters
options.action*T[]A closure that you implement to delete the selected items from the collection, and return them for addition to the Clipboard. The items must conform to the doc://com.apple.documentation/documentation/coretransferable/transferable protocol.
Return value
A view that sends one or more items to the Clipboard in response to a Cut command.
Discussion
Use this modifier to remove one or more items from a collection of items and then move the items to the Clipboard when someone issues a Cut command. People issue a Cut command by choosing Edit > Cut from the app's menu, or by using the Command-X keyboard shortcut. The system enables the Cut command for your app when it detects cuttable content.
For example, the following code enables people to remove bird names from a list of birds:
struct CuttableExample: View {
@State private var birds = ["owl", "parrot", "swift"]
@State private var selection: Set<String> = []
var body: some View {
List(birds, id: \.self, selection: $selection) {
Text($0)
}
.cuttable(for: String.self) {
for bird in selection {
birds.removeAll(where: { $0 == bird })
}
return Array(selection)
}
}
}When someone selects "owl" and issues a Cut command, the action
closure removes the selected item from the list and returns it.
In response, SwiftUI moves it to the Clipboard. If you want to
copy the item without removing it, use the copyable(_:) modifier
instead.
context menu item --- rather than using the system Cut command, update the Clipboard directly using an doc://com.apple.documentation/documentation/appkit/nspasteboard or a doc://com.apple.documentation/documentation/uikit/uipasteboard instance.
See also
More in Drag and drop.
- copyableSpecifies a list of items to copy in response to the system's Copy command.
- documentLaunchSubtitleSets the subtitle displayed beneath the title on the document launch card, using a localized string resource.
- documentLaunchTitleSets the title displayed on the document launch card, using a localized string resource.
- draggableActivates this view as the source of a drag and drop operation.
- dropConfigurationConfigures a drop session.
- dropDestinationDefines the destination of a drag and drop operation that provides a drop operation proposal and handles the dropped content with a closure that you specify.
- fileExporterPresents a system dialog allowing the user to export a Transferable item to a file on disk.
- fileExporterFilenameLabelOn macOS, configures the fileExporter with a label for the file name field.
- fileImporterPresents a system dialog for allowing the user to import multiple files.
- fileMoverPresents a system dialog for allowing the user to move an existing file to a new location.
- itemProviderProvides a closure that vends the drag representation to be used for a particular data element.
- pasteDestinationSpecifies an action that adds validated items to a view in response to the system's Paste command.