Unicode Scalars and Code Points
Access the underlying scalar values of text.
Unicode Scalars and Code Points is a free Swift Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Unicode Scalars
A Unicode scalar is a single code point in the Unicode standard, represented by Unicode.Scalar. Characters are built from one or more scalars.
let scalar: Unicode.Scalar = "A"
print(scalar)
print(scalar.value)The value Property
Each scalar has a numeric .value: its Unicode code point as a number. The letter A is 65.
let a: Unicode.Scalar = "A"
let z: Unicode.Scalar = "Z"
print(a.value, z.value)The unicodeScalars View
A string exposes its scalars through .unicodeScalars, a collection you can iterate.
for scalar in "Hi".unicodeScalars {
print(scalar, scalar.value)
}Scalars vs Characters
One Character may contain several scalars. An accented letter written with a combining mark has two scalars but one character.
let accented = "e\u{301}"
print("Characters:", accented.count)
print("Scalars:", accented.unicodeScalars.count)Code Points from Hex
You can write a scalar by its hex code point using the backslash-u escape with braces.
let heart = "\u{2764}"
print(heart)
for s in heart.unicodeScalars { print(s.value) }Creating Scalars from Numbers
You can construct a Unicode.Scalar from an integer code point; it is failable since not every number is valid.
if let s = Unicode.Scalar(65) {
print(s)
}Scalar Ranges
Because scalars have numeric values, you can compare and range over them, for example to test if a scalar is an ASCII digit.
let s: Unicode.Scalar = "7"
let isDigit = s.value >= 48 && s.value <= 57
print("Is digit:", isDigit)ASCII Property
A scalar has an .isASCII property telling you whether it falls in the ASCII range.
let a: Unicode.Scalar = "a"
let emoji: Unicode.Scalar = "\u{1F600}"
print(a.isASCII, emoji.isASCII)Scalar Properties
Scalars expose rich Unicode properties such as whether they are letters or whitespace via .properties.
let space: Unicode.Scalar = " "
print(space.properties.isWhitespace)Mapping Characters to Scalars
You can break a Character into its component scalars to inspect how it is composed.
let c: Character = "e\u{301}"
for s in c.unicodeScalars {
print(s.value)
}Why Scalars Matter
Working at the scalar level is essential for low-level text processing, encoding, and understanding how characters are composed.
let flag = "\u{1F1F9}\u{1F1F7}"
print("Characters:", flag.count)
print("Scalars:", flag.unicodeScalars.count)Quick Check
Recall the relationship between scalars and characters.
Recap: Unicode Scalars and Code Points
You learned that Unicode.Scalar is a single code point with a numeric .value, that strings expose a .unicodeScalars view, and that one Character may be composed of several scalars, which matters for low-level text work.
let text = "A\u{301}"
print("Characters:", text.count)
for s in text.unicodeScalars { print(s.value) }Frequently asked questions
Is the “Unicode Scalars and Code Points” lesson free?
Yes — the full text of “Unicode Scalars and Code Points” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.
What will I learn in “Unicode Scalars and Code Points”?
Access the underlying scalar values of text. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Unicode Scalars and Code Points” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Characters and Grapheme Clusters
- Unicode Scalars and Code Points
- Counting and Iterating Characters
- Encoding Views: utf8, utf16, unicodeScalars