enumerateDraggingItems(options:for:classes:searchOptions:using:)
Enumerates through each dragging item.
Declaration
func enumerateDraggingItems(options enumOpts: NSDraggingItemEnumerationOptions = [], for view: NSView?, classes classArray: [AnyClass], searchOptions: [NSPasteboard.ReadingOptionKey : Any] = [:], using block: (NSDraggingItem, Int, UnsafeMutablePointer<ObjCBool>) -> Void)Parameters
- enumOpts:
The enumeration options. See Nsdraggingitemenumerationoptions for the supported values.
- view:
The view to use as the base coordinate system for the Nsdraggingitem instances.
- classArray:
An array of class objects.
Arrange classes in the array in the preferred order of representation. Classes in the array must conform to the Nspasteboardreading protocol.
- searchOptions:
A dictionary that specifies options to refine the search for pasteboard items, such as restricting the search to file URLs with particular content types. For valid dictionary keys, see Readingoptionkey.
- block:
The block to execute for the enumeration. The block takes three arguments:
draggingItemA reference to the dragging item. The Draggingframe of the dragging item is in the coordinate space of the view that
viewspecifies. Aviewvalue ofnilmeans the screen coordinate space.idxThe index of the element in the classes.
stopA reference to a Boolean value that the block can use to stop the enumeration by setting
*stopto True.
Discussion
Enumerate through dragging items to modify their properties, such as the drag image or size, while the user is dragging. When the dragging items are over the destination, changes that the destination’s NSDraggingInfo methods make may override changes you make during the drag session.
To get dragging items in a data type that you expect while enumerating, specify classes in the classesArray parameter that implement the NSPasteboardReading protocol, such as NSImage, NSString, NSURL, NSColor, NSAttributedString, or NSPasteboardItem. For each item in the dragging pasteboard, the system performs the following steps:
The systems calls readableTypes(for:) on the item to determine the types of data the item conforms to.
It attempts to create an instance of a matching class from the dragging pasteboard data, using the class order you specify in the
classesArrayparameter.If it can create an instance of a matching class, the system creates an instance of NSDraggingItem with the class instance and the dragging properties of that item.
The system passes the
NSDraggingItemto the block you provide as thedraggingItemparameter.
If the system can’t create an instance of one of the classes you specify in classesArray with an item, the system skips the item without calling block and proceeds to the next item.
When the system provides a draggingItem to your block, modify the item’s properties to change how the user sees the item while dragging. Provide a view to this method if you want to express each dragging item’s draggingFrame relative to that view.
To refine the list of dragging items that this method provides, specify enumOpts and searchOptions.