encode(_:into:)
Encodes a Unicode scalar as a UTF-32 code unit by calling the given closure.
Declaration
static func encode(_ input: Unicode.Scalar, into processCodeUnit: (Unicode.UTF32.CodeUnit) -> Void)Parameters
- input:
The Unicode scalar value to encode.
- processCodeUnit:
A closure that processes one code unit argument at a time.
Discussion
For example, like every Unicode scalar, the musical fermata symbol (βπβ) can be represented in UTF-32 as a single code unit. The following code encodes a fermata in UTF-32:
var codeUnit: UTF32.CodeUnit = 0
UTF32.encode("π", into: { codeUnit = $0 })
print(codeUnit)
// Prints "119056"