Strings & Unicode — graphemes, indices, substrings, APIs
Understand Unicode-aware Strings: extended grapheme clusters, String.Index, substrings, common APIs (prefix/suffix/contains, split/join), and copy-on-write performance.
Unicode & graphemes
Swift String is Unicode-correct. One user-visible character may be multiple scalars (an extended grapheme cluster).
- Examples: emoji with skin tones, accented letters
- Count uses characters, not bytes
Counting characters
count measures characters (grapheme clusters), not bytes.
let wave = "👋🏽" // hand + skin tone modifier
let text = "Hi " + wave
print(text, "count =", text.count) // counts visible charactersAll lessons in this course
- Strings & Unicode — graphemes, indices, substrings, APIs
- Common APIs — prefix/suffix/contains, split/join
- Performance notes — copy-on-write