Type Method


Returns the high-surrogate code unit of the surrogate pair representing the specified Unicode scalar.


static func leadSurrogate(_ x: Unicode.Scalar) -> UTF16.CodeUnit



A Unicode scalar value. x must be represented by a surrogate pair when encoded in UTF-16. To check whether x is represented by a surrogate pair, use UTF16.width(x) == 2.

Return Value

The leading surrogate code unit of x when encoded in UTF-16.


Because a Unicode scalar value can require up to 21 bits to store its value, some Unicode scalars are represented in UTF-16 by a pair of 16-bit code units. The first and second code units of the pair, designated leading and trailing surrogates, make up a surrogate pair.

let apple: Unicode.Scalar = "🍎"
// Prints "55356"