[swift-evolution] InternalString class for easy String manipulation
spestov at apple.com
Tue Aug 16 20:58:57 CDT 2016
> On Aug 14, 2016, at 3:41 PM, Michael Savich via swift-evolution <swift-evolution at swift.org> wrote:
> What about having an InternalString subclass that only supports one encoding, allowing it to be subscripted with Ints? The idea is that an InternalString is for Strings that are more or less hard coded into the app. Dictionary keys, enum raw values, that kind of stuff. This also has the added benefit of forcing the programmer to think about what the String is being used for. Is it user facing? Or is it just for internal use? And of course, it makes code dealing with String manipulation much more concise and readable.
If you actually just want an ASCII string, you can just use an Array<UInt8> and avoid all the complexity of Unicode altogether. You won’t get the string literal syntax, but if you’re really adventurous you can wrap it in a new struct type, and define an ExpressibleByStringLiteral conformance.
More information about the swift-evolution