---
title: "dragFile(_:from:slideBack:event:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/dragfile(_:from:slideback:event:)"
---

# dragFile(_:from:slideBack:event:)

Initiates a dragging operation from the view, allowing the user to drag a file icon to any application that has window or view objects that accept files.

## Declaration

```swift
func dragFile(_ filename: String, from rect: NSRect, slideBack flag: Bool, event: NSEvent) -> Bool
```

## Parameters

- `filename`: A string that specifies the absolute path for the file that is dragged.
- `rect`: A rectangle that describes the position of the icon in the view’s coordinate system.
- `flag`: A Boolean that indicates whether the icon being dragged should slide back to its position in the view if the file isn’t accepted. The icon slides back to aRect if slideBack is doc://com.apple.documentation/documentation/Swift/true, the file is not accepted by the dragging destination, and the user has not disabled icon animation; otherwise it simply disappears.
- `event`: The mouse-down event object from which to initiate the drag operation. In particular, its mouse location is used for the offset of the icon being dragged.

## Return Value

Return Value true if the view successfully initiates the dragging operation (which doesn’t necessarily mean the dragging operation concluded successfully). Otherwise, this method returns false.

## Discussion

Discussion This method must be invoked only within an implementation of the mouseDown(with:) method. See the NSDraggingSource, NSDraggingInfo, and NSDraggingDestination protocol specifications for more information on dragging operations.

## See Also

### Related Documentation

- [shouldDelayWindowOrdering(for:)](appkit/nsview/shoulddelaywindowordering(for:).md)

### Methods

- [lockFocus()](appkit/nsview/lockfocus().md)
- [lockFocusIfCanDraw()](appkit/nsview/lockfocusifcandraw().md)
- [lockFocusIfCanDraw(in:)](appkit/nsview/lockfocusifcandraw(in:).md)
- [unlockFocus()](appkit/nsview/unlockfocus().md)
- [scroll(_:by:)](appkit/nsview/scroll(_:by:).md)
- [shouldDrawColor()](appkit/nsview/shoulddrawcolor().md)
- [allocateGState()](appkit/nsview/allocategstate().md)
- [gState()](appkit/nsview/gstate().md)
- [setUpGState()](appkit/nsview/setupgstate().md)
- [renewGState()](appkit/nsview/renewgstate().md)
- [releaseGState()](appkit/nsview/releasegstate().md)
- [dragPromisedFiles(ofTypes:from:source:slideBack:event:)](appkit/nsview/dragpromisedfiles(oftypes:from:source:slideback:event:).md)
