Instance Methodswift 6.1.2Swift

withUTF8Buffer(_:)

Invokes the given closure with a buffer containing the static string’s UTF-8 code unit sequence (excluding the null terminator).

func withUTF8Buffer<R>(_ body: (UnsafeBufferPointer<UInt8>) -> R) -> R

Parameters

body

A closure that takes a buffer pointer to the static string’s UTF-8 code unit sequence as its sole argument. If the closure has a return value, that value is also used as the return value of the withUTF8Buffer(_:) method. The pointer argument is valid only for the duration of the method’s execution.

Returns

The return value, if any, of the body closure.

This method works regardless of whether the static string stores a pointer or a single Unicode scalar value.

The pointer argument to body is valid only during the execution of withUTF8Buffer(_:). Do not store or return the pointer for later use.