0Pricing
Swift Academy · Lesson

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 characters

All lessons in this course

  1. Strings & Unicode — graphemes, indices, substrings, APIs
  2. Common APIs — prefix/suffix/contains, split/join
  3. Performance notes — copy-on-write
← Back to Swift Academy