<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchIO",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:objc(cs)OS_dispatch_io"
  },
  "title" : "DispatchIO"
}
-->

# DispatchIO

An object that manages operations on a file descriptor using either stream-based or random-access semantics.

```
class DispatchIO
```

## Topics

### Creating a Dispatch I/O Object

[`init(type:fileDescriptor:queue:cleanupHandler:)`](/documentation/Dispatch/DispatchIO/init(type:fileDescriptor:queue:cleanupHandler:))

Creates a new I/O channel that accesses the specified file descriptor.

[`init(type:path:oflag:mode:queue:cleanupHandler:)`](/documentation/Dispatch/DispatchIO/init(type:path:oflag:mode:queue:cleanupHandler:)-50rb0)

Creates a new I/O channel that accesses the file at the specified path, potentially creating that file in the process.

[`init(type:io:queue:cleanupHandler:)`](/documentation/Dispatch/DispatchIO/init(type:io:queue:cleanupHandler:))

Creates a new I/O channel from an existing I/O channel.

[`StreamType`](/documentation/Dispatch/DispatchIO/StreamType)

The semantics for accessing the contents of a file descriptor.

### Reading from the File

[`read(offset:length:queue:ioHandler:)`](/documentation/Dispatch/DispatchIO/read(offset:length:queue:ioHandler:))

Schedules an asynchronous read operation on the specified channel.

[`read(fromFileDescriptor:maxLength:runningHandlerOn:handler:)`](/documentation/Dispatch/DispatchIO/read(fromFileDescriptor:maxLength:runningHandlerOn:handler:))

Schedules an asynchronous read operation using the specified file descriptor.

### Writing to the File

[`write(offset:data:queue:ioHandler:)`](/documentation/Dispatch/DispatchIO/write(offset:data:queue:ioHandler:))

Schedules an asynchronous write operation for the specified channel.

[`write(toFileDescriptor:data:runningHandlerOn:handler:)`](/documentation/Dispatch/DispatchIO/write(toFileDescriptor:data:runningHandlerOn:handler:))

Schedules an asynchronous write operation to the specified file descriptor.

### Closing the File

[`close(flags:)`](/documentation/Dispatch/DispatchIO/close(flags:))

Closes the channel to new read and write operations.

[`CloseFlags`](/documentation/Dispatch/DispatchIO/CloseFlags)

Additional flags to use when closing an I/O channel.

### Managing the File Descriptor

[`dispatch_io_get_descriptor`](/documentation/Dispatch/DispatchIO/fileDescriptor)

Returns the file descriptor associated with the specified channel.

[`dispatch_io_set_high_water`](/documentation/Dispatch/DispatchIO/setLimit(highWater:))

Sets the maximum number of bytes to process before enqueueing a handler block.

[`dispatch_io_set_low_water`](/documentation/Dispatch/DispatchIO/setLimit(lowWater:))

Sets the minimum number of bytes to process before enqueueing a handler block.

[`setInterval(interval:flags:)`](/documentation/Dispatch/DispatchIO/setInterval(interval:flags:))

Sets the interval, in nanoseconds, at which to invoke the I/O handlers for the channel.

[`IntervalFlags`](/documentation/Dispatch/DispatchIO/IntervalFlags)

The desired delivery behavior for interval events.

### Synchronizing File Operations

[`dispatch_io_barrier`](/documentation/Dispatch/DispatchIO/barrier(execute:))

Schedules a barrier operation on the specified channel.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherits From

[`DispatchObject`](/documentation/Dispatch/DispatchObject)

---

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)