<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/dragFile(_:from:slideBack:event:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(im)dragFile:fromRect:slideBack:event:"
  },
  "title" : "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.

```
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

<doc://com.apple.documentation/documentation/Swift/true> if the view successfully initiates the dragging operation (which doesn’t necessarily mean the dragging operation concluded successfully). Otherwise, this method returns <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

This method must be invoked only within an implementation of the [`mouseDown(with:)`](/documentation/AppKit/NSResponder/mouseDown(with:)) method.

See the [`NSDraggingSource`](/documentation/AppKit/NSDraggingSource), [`NSDraggingInfo`](/documentation/AppKit/NSDraggingInfo), and [`NSDraggingDestination`](/documentation/AppKit/NSDraggingDestination) protocol specifications for more information on dragging operations.

## See Also

[`dragImage:at:offset:event:pasteboard:source:slideBack:`](/documentation/AppKit/NSView/dragImage:at:offset:event:pasteboard:source:slideBack:)

Initiates a dragging operation from the view, allowing the user to drag arbitrary data with a specified icon into any application that has window or view objects that accept dragged data.

[`shouldDelayWindowOrdering(for:)`](/documentation/AppKit/NSView/shouldDelayWindowOrdering(for:))

Allows the user to drag objects from the view without activating the app or moving the window of the view forward, possibly obscuring the destination.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)