0Pricing
Swift Academy · Lesson

Characters and Grapheme Clusters

See why one Character can be several scalars.

The Character Type

In Swift, the Character type represents a single human-readable character. A String is a collection of these characters.

let letter: Character = "A"
print(letter)
print(type(of: letter))

Character vs String

A double-quoted literal is a String by default. Annotate the type as Character to get a single character value.

let s = "A"
let c: Character = "A"
print(type(of: s), type(of: c))

All lessons in this course

  1. Characters and Grapheme Clusters
  2. Unicode Scalars and Code Points
  3. Counting and Iterating Characters
  4. Encoding Views: utf8, utf16, unicodeScalars
← Back to Swift Academy