---
title: "write(_:completionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/nwtcpconnection/write(_:completionhandler:)"
---

# write(_:completionHandler:)

Write the data to the connection.

## Declaration

```swift
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

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

## See Also

### Transferring data

- [readMinimumLength(_:maximumLength:completionHandler:)](networkextension/nwtcpconnection/readminimumlength(_:maximumlength:completionhandler:).md)
- [readLength(_:completionHandler:)](networkextension/nwtcpconnection/readlength(_:completionhandler:).md)
- [writeClose()](networkextension/nwtcpconnection/writeclose().md)
