leadSurrogate(_:)
Returns the high-surrogate code unit of the surrogate pair representing the specified Unicode scalar.
static func leadSurrogate(_ x: Unicode.Scalar) -> UTF16.CodeUnit
Parameters
- x
A Unicode scalar value.
x
must be represented by a surrogate pair when encoded in UTF-16. To check whetherx
is represented by a surrogate pair, useUTF16.width(x) == 2
.
Returns
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 = "🍎"
print(UTF16.leadSurrogate(apple))
// Prints "55356"