Required Static Methodswift 6.0.1Swift

    encode(_:into:)

    Encodes a Unicode scalar as a series of code units by calling the given closure on each code unit.

    static func encode(_ input: Unicode.Scalar, into processCodeUnit: (Self.CodeUnit) -> Void)

    Parameters

    input

    The Unicode scalar value to encode.

    processCodeUnit

    A closure that processes one code unit argument at a time.

    For example, the musical fermata symbol (β€œπ„β€) is a single Unicode scalar value (\u{1D110}) but requires four code units for its UTF-8 representation. The following code uses the UTF8 codec to encode a fermata in UTF-8:

    var bytes: [UTF8.CodeUnit] = []
    UTF8.encode("𝄐", into: { bytes.append($0) })
    print(bytes)
    // Prints "[240, 157, 132, 144]"

    Other requirements

    Type members

    • init()

      Creates an instance of the codec.

    Instance members