UTF-8 String

Swift 5 switches the preferred encoding of strings from UTF-16 to UTF-8 while preserving efficient Objective-C-interoperability. Because the String type abstracts away these low-level concerns, no source-code changes from developers should be necessary*, but it’s worth highlighting some of the benefits this move gives us now and in the future.

Switching to UTF-8 fulfills one of String’s long-term goals to enable high-performance processing, which is the most passionate request from performance-sensitive developers. It also lays the groundwork for providing even more performant APIs in the future. String’s preferred encoding is baked into Swift’s ABI for performance, so it was imperative that this switch happen in time for ABI stability in Swift 5.

swift.org/blog/utf8-string/

Swift 5 changes String's preferred encoding from UTF-16 to UTF-8 for better performance in modern computing, like server-side work and C interop, while keeping efficient Objective-C bridging.

This unified storage cuts complexity, boosts optimizations, and adds small-string support for non-ASCII on 64-bit and 32-bit platforms. For Objective-C APIs needing UTF-16, Swift uses "breadcrumbs" for fast index mapping without full transcoding, and deprecates misused features like String.Index.encodedOffset to avoid issues.


Category:

Tag:

Year: