Instance Method

enumerateDraggingItems(options:for:classes:searchOptions:using:)

Required.

Enumerates through each dragging item.

Declaration

func enumerateDraggingItems(options enumOpts: NSDraggingItemEnumerationOptions = [], for view: NSView?, classes classArray: [AnyClass], searchOptions: [String : Any] = [:], using block: @escaping (NSDraggingItem, Int, UnsafeMutablePointer<ObjCBool>) -> Void)

Parameters

enumOpts

The enumeration options. See NSDraggingItemEnumerationOptions for the supported values.

view

The view used as the base coordinate system for the NSDraggingItem instances.

classArray

An array of class objects.

The classes should appear in the array in the order the preferred order of representation. Classes in the array must conform to the NSPasteboardReading Protocol Reference.

searchOptions

A dictionary that specifies options to refine the search for pasteboard items, for example to restrict the search to file URLs with particular content types. For valid dictionary keys, see NSPasteboardReadingOptions.

block

The block executed for the enumeration.

The block takes three arguments:

draggingItem

A reference to the dragging item. The draggingFrame of the dragging item is in the coordinate space of the view specified in by view. A view value of nil means the screen coordinate space.

idx

The index of the element in the classes.

stop

A reference to a Boolean value that the block can use to stop the enumeration by setting *stop to true; it should not touch *stop otherwise.

Discussion

Classes in the provided array must implement the NSPasteboardReading protocol. Cocoa classes that implement this protocol include NSImage, NSString, NSURL, NSColor, NSAttributedString, and NSPasteboardItem. For every item on the pasteboard, each class in the provided array will be queried for the types it can read using readableTypes(for:). An instance is created of the first class found in the provided array whose readable types match a conforming type contained in that pasteboard item. Any instances that could be created from pasteboard item data is returned to the caller. Additional options, such as restricting the search to file URLs with particular content types, can be specified with the options dictionary. Only objects of the requested classes are returned. You can always ensure to receive one object per item on the pasteboard by including the NSPasteboardItem class in the array of classes.

This method enumerates the items on the dragging pasteboard associated with this dragging info, as well as all the additional data the dragging info knows about. The pasteboard data and the additional data is represented as one logical unit, an NSDraggingItem instance.

For every item on the pasteboard, each class in classArray will be queried for the types it can read using readableTypes(for:). An instance will be created of the first class found in the provided array whose readable types match a conforming type contained in that pasteboard item. If an instance is created from the pasteboard item data, it is placed into an NSDraggingItem along with the dragging properties of that item such as the dragging image. The NSDraggingItem instance is then passed as a parameter to the provided block.

See Also

Related Symbols

func readObjects(forClasses: [AnyClass], options: [String : Any]? = nil)

Reads from the receiver objects that best match the specified array of classes.