<!--
{
  "availability" : [
    "iOS: 8.0.0 - 16.0.0",
    "iPadOS: 8.0.0 - 16.0.0",
    "macCatalyst: 8.0.0 - 16.0.0",
    "macOS: 10.10.0 - 13.0.0",
    "tvOS: 9.0.0 - 16.0.0",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 - 9.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/String/init(bytesNoCopy:length:encoding:freeWhenDone:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS10FoundationE11bytesNoCopy6length8encoding12freeWhenDoneSSSgSv_SiSSAAE8EncodingVSbtcfc"
  },
  "title" : "init(bytesNoCopy:length:encoding:freeWhenDone:)"
}
-->

# init(bytesNoCopy:length:encoding:freeWhenDone:)

Creates a new string that contains the specified number of bytes from the
given buffer, interpreted in the specified encoding, and optionally
frees the buffer.

```
init?(bytesNoCopy bytes: UnsafeMutableRawPointer, length: Int, encoding: String.Encoding, freeWhenDone flag: Bool)
```

## Discussion> Warning: This initializer is not memory-safe!

---

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)