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
- Characters and Grapheme Clusters
- Unicode Scalars and Code Points
- Counting and Iterating Characters
- Encoding Views: utf8, utf16, unicodeScalars