Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift `String.Encoding`: `.unicode` vs `.utf16`

String.Encoding struct features several unicode related implementations:

https://developer.apple.com/documentation/swift/string/encoding

  • utf8
  • utf16 and its modifications
  • utf32 and its modifications
  • and suddenly, unicode

What is this unicode case, what’s it for? Is this just an alias to some particular encoding like utf16? Or maybe, this is just some umbrella value which means "any unicode encoding" and in some contexts it will evaluate to utf8, and in some – to utf16?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Looking at the source code for swift-corelibs-foundation, utf16 is the same as unicode:

public static let utf16 = Encoding.unicode

This makes sense, as the NSStringEncoding (which presumably is what the cases of String.Encoding are based on) values are also like this. The docs for NSUTF16StringEncoding says it is an alias of NSUnicodeStringEncoding.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading