<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/fileDescriptor",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(py)fileDescriptor"
  },
  "title" : "fileDescriptor"
}
-->

# fileDescriptor

The POSIX file descriptor associated with the receiver.

```
var fileDescriptor: Int32 { get }
```

## Discussion

You can use this method to retrieve the file descriptor while it is open. If the file handle object owns the file descriptor, you must not close it yourself. However, you can use the [`closeFile()`](/documentation/Foundation/FileHandle/closeFile()) method to close the file descriptor programmatically. If you do call the [`closeFile()`](/documentation/Foundation/FileHandle/closeFile()) method, subsequent calls to this method raise an exception.

## See Also

[`init(fileDescriptor:)`](/documentation/Foundation/FileHandle/init(fileDescriptor:))

Creates and returns a file handle object associated with the specified file descriptor.



---

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)