Generic Instance Method 総称体インスタンスメソッド

withCString(encodedAs:_:)

Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of code units. null終端のコード単位シーケンスとして表される、文字列の内容へのポインタとともに与えられたクロージャを呼び出します。

Declaration 宣言

func withCString<Result, TargetEncoding>(encodedAs targetEncoding: TargetEncoding.Type, _ body: (UnsafePointer<TargetEncoding.CodeUnit>) throws -> Result) rethrows -> Result where TargetEncoding : _UnicodeEncoding

Parameters パラメータ

body

A closure with a pointer parameter that points to a null-terminated sequence of code units. If body has a return value, that value is also used as the return value for the withCString(encodedAs:_:) method. The pointer argument is valid only for the duration of the method’s execution. コード単位からなるnull終端シーケンスを指し示すポインタパラメータを持つクロージャ。bodyが戻り値を持つならば、その値はまたwithCString(encodedAs:_:)メソッドの戻り値としても使われます。ポインタ引数は、ただメソッドの実行の間に対してのみ有効です。

targetEncoding

The encoding in which the code units should be interpreted. それでコード単位が解釈されるべきエンコーディング。

Return Value 戻り値

The return value, if any, of the body closure parameter. bodyクロージャパラメータの戻り値、もしあれば。

Discussion 解説

The pointer passed as an argument to body is valid only during the execution of withCString(encodedAs:_:). Do not store or return the pointer for later use. 引数としてbodyに渡されるポインタは、withCString(encodedAs:_:)の実行の間のみ有効です。後で使うためにポインタを格納したり返したりしないでください。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Getting C Strings C文字列を扱う