Type Method 型メソッド

encode(_:into:)

Encodes a Unicode scalar as a series of code units by calling the given closure on each code unit. 与えられたクロージャを各コード単位上で呼び出すことによって、ユニコードスカラーを一連のコード単位としてエンコードします。

Declaration 宣言

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

Parameters パラメータ

input

The Unicode scalar value to encode. エンコードするあるユニコードスカラー値。

processCodeUnit

A closure that processes one code unit argument at a time. あるクロージャ、それは一度に1つのコードユニット引数を処理します。

Discussion 解説

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 encodes a fermata in UTF-8: 例えば、音楽のフェルマータ符号(“𝄐”)は単一のユニコードスカラー値(\u{1D110})ですが4つのコード単位をそれのUTF-8表現のために必要とします。以下のコードはフェルマータをUTF-8でエンコードします:


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

Relationships 関係

From Protocol 由来プロトコル