---
title: "write(_:withCompletionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/neappproxytcpflow/write(_:withcompletionhandler:)"
---

# write(_:withCompletionHandler:)

Write data to the flow.

## Declaration

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

```swift
func write(_ data: Data) async throws
```

## Parameters

- `data`: An doc://com.apple.documentation/documentation/Foundation/NSData object containing the data to write.
- `completionHandler`: A block that will be executed by the system on an internal system thread when the data is written into the receive buffer of the socket associated with the flow. The caller should use this callback as an indication that it is possible to write more data to the flow without using up excessive buffer memory. If an error occurs while writing the data then a non-nil doc://com.apple.documentation/documentation/Foundation/NSError object is passed to the block. See NEAppProxyFlowError in doc://com.apple.networkextension/documentation/NetworkExtension/NEAppProxyFlow for a list of possible errors.

## Mentioned in

Handling Flow Copying

## See Also

### Handling flow data

- [readData(completionHandler:)](networkextension/neappproxytcpflow/readdata(completionhandler:).md)
