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

# readLength(_:completionHandler:)

Read a certain number of bytes on a connection.

## Declaration

```swift
func readLength(_ length: Int, completionHandler completion: @escaping (Data?, (any Error)?) -> Void)
```

## Parameters

- `length`: The exact number of bytes the caller wants to read.
- `completion`: The completion handler to be invoked when data has been read or an error occurred.

## Discussion

Discussion Read length number of bytes. See readMinimumLength:maximumLength:completionHandler: for a complete discussion of the callback behavior.

## See Also

### Transferring data

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