I've implemented a macOS app that displays a table of records in a document using SwiftUI. However, I want to allow the user to copy selected records. I've tried adding onCopyCommand, but I'm not seeing Edit -> Copy enabled.
HSplitView {
Table(records, selection: $selectedRecordIDs) {
TableColumn("Timestamp", value: \.timestamp.description)
TableColumn("Message", value: \.message)
.width(ideal: columnWeight.message * geometry.size.width)
}
.onCopyCommand {
[NSItemProvider(item: "Hello, World!" as NSString, typeIdentifier: UTType.plainText.identifier)]
}
How to enabled Copy?
Thanks.
-
—
tompmtv
Add a CommentI couldn't find a way to support record selections copying using
onCopyCommandso I instead just removed the pasteboard group from the menu and implemented my own Copy command usingCommandGroup(replacing: .pasteboard). I usedFocusedValuesto keep track of the selected records.