Home > Enterprise >  How would you implement multiple items using NSOUtlineViews's pasteboardWriterForItem:
How would you implement multiple items using NSOUtlineViews's pasteboardWriterForItem:

Time:10-26

I am using an NSOutlineView with drag and drop support. There is an NSOutlineViewDataSource function entitled outlineView(_:pasteboardWriterForItem:).

This call serializes the item passed into the function and allows the user to retrieve the serialized item in outlineView(_:acceptDrop:item:childIndex:)

    @MainActor optional func outlineView(
    _ outlineView: NSOutlineView,
    acceptDrop info: NSDraggingInfo,
    item: Any?,
    childIndex index: Int
) -> Bool

That being said, I don't understand how I would write multiple rows of data using outlineView(_:pasteboardWriterForItem:) . It gets called for each item being moved, but the pasteboard only keeps a reference to the last item. Apple deprecated several multiple row write/move functions.

How should I implement this? I have tried several solutions but they're hacky and seem like they're not the canonical solution.

CodePudding user response:

The information is in the info parameter.

There is an API enumerateDraggingItems(options:for:classes:searchOptions:using:) of NSDraggingInfo to enumerate and proceed the items.

In outlineView(_:pasteboardWriterForItem:) you usually just

return item as? NSPasteboardWriting
  • Related