---
title: "enumerateDraggingItems(options:for:classes:searchOptions:using:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdraggingsession/enumeratedraggingitems(options:for:classes:searchoptions:using:)"
---

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

Enumerates through each dragging item.

## Declaration

```swift
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 doc://com.apple.appkit/documentation/AppKit/NSDraggingItemEnumerationOptions for the supported values.
- `view`: The view to use as the base coordinate system for the doc://com.apple.appkit/documentation/AppKit/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 doc://com.apple.appkit/documentation/AppKit/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 doc://com.apple.appkit/documentation/AppKit/NSPasteboard/ReadingOptionKey.
- `block`: The block to execute for the enumeration. The block takes three arguments:

## Discussion

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 classesArray parameter. 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 NSDraggingItem to the block you provide as the draggingItem parameter. 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. tip: Ensure you receive one object per item on the pasteboard by including the NSPasteboardItem class in the array of classes. 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. warning: The draggingItem object is only valid for the current iteration of the enumeration block. Never store the draggingItem or change it outside of the block iteration. Don’t reference draggingItem inside an imageComponentsProvider block for the following reasons: ・When the system calls the imageComponentsProvider block, the enumeration block is out of scope and the draggingItem is no longer valid. ・Referencing draggingItem in an imageComponentsProvider block creates a retain cycle because draggingItem retains imageComponentsProvider, and imageComponentsProvider retains draggingItem. Assign draggingItem.item to an object pointer or variable outside of the imageComponentsProvider block definition instead, and use that object pointer or variable inside the imageComponentsProvider block definition. To refine the list of dragging items that this method provides, specify enumOpts and searchOptions.

## See Also

### Related Documentation

- [readObjects(forClasses:options:)](appkit/nspasteboard/readobjects(forclasses:options:).md)
