<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFStringGetMaximumSizeForEncoding(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFStringGetMaximumSizeForEncoding"
  },
  "title" : "CFStringGetMaximumSizeForEncoding(_:_:)"
}
-->

# CFStringGetMaximumSizeForEncoding(_:_:)

Returns the maximum number of bytes a string of a specified length (in Unicode characters) will take up if encoded in a specified encoding.

```
func CFStringGetMaximumSizeForEncoding(_ length: CFIndex, _ encoding: CFStringEncoding) -> CFIndex
```

## Parameters

`length`

The number of Unicode characters to evaluate.

`encoding`

The string encoding for the number of characters specified by `length`.

## Return Value

The maximum number of bytes that could be needed to represent `length` number of Unicode characters with the string encoding `encoding`, or [`kCFNotFound`](/documentation/CoreFoundation/kCFNotFound) if the number exceeds `LONG_MAX`.

## Discussion

The number of bytes that the encoding actually ends up requiring when converting any particular string could be less than the returned value, but never more.

---

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)