Generic Function

withVaList(_:_:)

Invokes the given closure with a C va_list argument derived from the given array of arguments.

Declaration

func withVaList<R>(_ args: [CVarArg], _ body: (CVaListPointer) -> R) -> R

Parameters

args

An array of arguments to convert to a C va_list pointer.

body

A closure with a CVaListPointer parameter that references the arguments passed as args. If body has a return value, that value is also used as the return value for the withVaList(_:) function. The pointer argument is valid only for the duration of the function’s execution.

Return Value

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

Discussion

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

See Also

C Variadic Functions

struct CVaListPointer

A wrapper around a C va_list pointer.

protocol CVarArg

A type whose instances can be encoded, and appropriately passed, as elements of a C va_list.

func getVaList([CVarArg])

Returns a CVaListPointer that is backed by autoreleased storage, built from the given array of arguments.