<!--
{
  "availability" : [
    "iOS: 9.0.0 - 18.0.0",
    "iPadOS: 9.0.0 - 18.0.0",
    "macCatalyst: 13.1.0 - 18.0.0",
    "macOS: 10.11.0 - 15.0.0",
    "tvOS: 17.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NWTCPConnection/write(_:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NWTCPConnection(im)write:completionHandler:"
  },
  "title" : "write(_:completionHandler:)"
}
-->

# write(_:completionHandler:)

Write the data to the connection.

```
func write(_ data: Data, completionHandler completion: @escaping ((any Error)?) -> Void)
```

## Parameters

`data`

The data object whose content will be written.

`completion`

The completion handler to be invoked when the data content has been written or an error has occurred.
If `error` is `nil`, the write succeeded and the caller can write more data.

## Discussion

Callers should wait until the `completionHandler` is executed before issuing another write.

---

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)