<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchIO/write(offset:data:queue:ioHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "s:So14OS_dispatch_ioC8DispatchE5write6offset4data5queue0C7Handlerys5Int64V_AC0D4DataVSo0a1_b1_H0CySb_ALSgs5Int32VtctF"
  },
  "title" : "write(offset:data:queue:ioHandler:)"
}
-->

# write(offset:data:queue:ioHandler:)

Schedules an asynchronous write operation for the specified channel.

```
func write(offset: off_t, data: DispatchData, queue: DispatchQueue, ioHandler: @escaping (Bool, DispatchData?, Int32) -> Void)
```

## Parameters

`offset`

For random-access channels, this parameter specifies the offset into the channel at which to write. The offset is specified relative to the initial file pointer of the channel’s file descriptor at the time the channel was created.
For stream-based channels, this parameter is ignored and data is written to the current position.

`data`

The data to write to the channel.

`queue`

The dispatch queue on which to submit the `ioHandler` closure.

`ioHandler`

The closure to use to report any progress. This block may be queued multiple times to process a given data request. Each time the block is queued, the `data` parameter passed to the handler contains the data that remains to be written.
Your closure need not be reentrant. The system guarantees that only one instance of this closure is executed at any given time.

## Discussion

This function writes the specified data and submits the `io_handler` block to the `queue` to report on the progress of the operation. If the `done` parameter of the handler is set to <doc://com.apple.documentation/documentation/Swift/false>, it means that only part of the data was written. If the `done` parameter is set to <doc://com.apple.documentation/documentation/Swift/true>, it means the write operation is complete and the handler is not submitted again. If the operation was successful, the handler’s `error` parameter is set to `0`. However, if an unrecoverable error occurs on the channel’s file descriptor, the `done` parameter is set to <doc://com.apple.documentation/documentation/Swift/true> and an appropriate error value is reported in the handler’s `error` parameter.

---

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)