---
title: "beginDraggingSession(items:gesture:source:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/begindraggingsession(items:gesture:source:)"
---

# beginDraggingSession(items:gesture:source:)

Initiates a drag operation using a gesture recognizer.

## Declaration

```swift
func beginDraggingSession(items: [NSDraggingItem], gesture: NSGestureRecognizer, source: any NSDraggingSource) -> NSDraggingSession?
```

## Parameters

- `items`: The dragging items. The frame property of each doc://com.apple.appkit/documentation/AppKit/NSDraggingItem must be in the view’s coordinate system.
- `gesture`: The gesture recognizer initiating the drag session.
- `source`: An object that controls the dragging operation and conforms to the doc://com.apple.appkit/documentation/AppKit/NSDraggingSource protocol.

## Return Value

Return Value The dragging session for the drag, or nil if the method can’t start the session.

## Discussion

Discussion Like beginDraggingSession(with:event:source:), this method starts an internal tracking loop. If the gesture is mouse-based, the system cancels the gesture at the end of the drag-and-drop operation. If the gesture is touch-based, the system cancels the gesture at the start of the drag-and-drop operation. The system may animate drag images from their initial positions into a system-defined formation. The system clips the drag to the visible area of the view. var dragSession: NSDraggingSession?

@objc func handleDragGesture(_ gestureRecognizer: NSGestureRecognizer) {     if gestureRecognizer.state == .began {         let items = [NSDraggingItem(pasteboardWriter: myPasteboardItem)]                  // Returns nil if the drag fails to start.         dragSession = self.beginDraggingSession(items: items, gesture: gestureRecognizer, source: self)     } }

## See Also

### Related Documentation

- [beginDraggingSession(with:event:source:)](appkit/nsview/begindraggingsession(with:event:source:).md)

### Dragging Operations

- [registerForDraggedTypes(_:)](appkit/nsview/registerfordraggedtypes(_:).md)
- [unregisterDraggedTypes()](appkit/nsview/unregisterdraggedtypes().md)
- [registeredDraggedTypes](appkit/nsview/registereddraggedtypes.md)
- [beginDraggingSession(with:event:source:)](appkit/nsview/begindraggingsession(with:event:source:).md)
- [shouldDelayWindowOrdering(for:)](appkit/nsview/shoulddelaywindowordering(for:).md)
