3 ms·
Swift's String class (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html https://develo
by panic 12y ago
Swift's String class (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html https://developer.apple.com/library/ios/documentation/Swift/...) uses extended grapheme clusters as characters. If you need the raw Unicode scalars or UTF-16/UTF-8 code units, there are separate "views" into the string that let you iterate over these.
Using extended grapheme clusters as characters means truncation, concatenation, length measurement and transformations like reversal all work in the expected way, even in the presence of combining characters. More standard libraries should consider adopting this model!
- TheLoneWolfling 12y agoSo does Swift use a rope? Or is getting the Nth character of a string O(n) time?
- thomasballinger 12y agoHow do you find this in practice? I mention this in the 3rd footnote of the post, but didn't have much to say about it because I haven't used it myself. The one person I've talked about this says it's rather awkward right now because Swift doesn't provide great tools for working with these objects.