Operating on [UInt8]
text buffers (“bytestrings”) is a common programming task. A popular approach among some Swift users is to (ab)use the String
API, and attempt to spell familiar C-idioms using its syntax. This has the major bonus of readability, but leaves users vulnerable to many pitfalls.
A common mistake is to convert bytestrings to String
s and compare them to other String
s. Given two bytestrings a:[UInt8]
, b:[UInt8]
, many users assume that
String(decoding: a, as: Unicode.ASCII.self) ==
String(decoding: b, as: Unicode.ASCII.self)