---
title: "maximumLengthOfBytes(using:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/maximumlengthofbytes(using:)"
---

# maximumLengthOfBytes(using:)

Returns the maximum number of bytes needed to store the receiver in a given encoding.

## Declaration

```swift
func maximumLengthOfBytes(using enc: UInt) -> Int
```

## Parameters

- `enc`: The encoding for which to determine the receiver’s length.

## Return Value

Return Value The maximum number of bytes needed to store the receiver in encoding in a non-external representation. The length does not include space for a terminating NULL character. Returns 0 if the amount of memory required for storing the results of the encoding conversion would exceed NSIntegerMax.

## Discussion

Discussion The result is an estimate and is returned in O(1) time; the estimate may be considerably greater than the actual length needed.

## See Also

### Getting a String’s Length

- [length](foundation/nsstring/length.md)
- [lengthOfBytes(using:)](foundation/nsstring/lengthofbytes(using:).md)
