---
title: "init(fileDescriptor:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/filehandle/init(filedescriptor:)"
---

# init(fileDescriptor:)

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

## Declaration

```swift
convenience init(fileDescriptor fd: Int32)
```

## Parameters

- `fd`: The POSIX file descriptor with which to initialize the file handle. This descriptor represents an open file or socket that you created previously. For example, when creating a file handle for a socket, you’d pass the value returned by the socket function.

## Return Value

Return Value A file handle initialized with fileDescriptor.

## Discussion

Discussion The file descriptor you pass in to this method isn’t owned by the file handle object. Therefore, you’re responsible for closing the file descriptor at some point after disposing of the file handle object. You can create a file handle for a socket by using the result of a socket call as fileDescriptor.

## See Also

### Related Documentation

- [closeFile()](foundation/filehandle/closefile().md)

### Creating a file handle

- [init(fileDescriptor:closeOnDealloc:)](foundation/filehandle/init(filedescriptor:closeondealloc:).md)
- [init(forReadingAtPath:)](foundation/filehandle/init(forreadingatpath:).md)
- [init(forReadingFromURL:)](foundation/filehandle/init(forreadingfromurl:).md)
- [init(forWritingAtPath:)](foundation/filehandle/init(forwritingatpath:).md)
- [init(forWritingToURL:)](foundation/filehandle/init(forwritingtourl:).md)
- [init(forUpdatingAtPath:)](foundation/filehandle/init(forupdatingatpath:).md)
- [init(forUpdatingURL:)](foundation/filehandle/init(forupdatingurl:).md)
- [init(coder:)](foundation/filehandle/init(coder:).md)
