Instances of conforming types can be encoded, and appropriately passed, as elements of a C va_list.


This protocol is useful in presenting C “varargs” APIs natively in Swift. It only works for APIs that have a va_list variant, so for example, it isn’t much use if all you have is:

int c_api(int n, ...)

Given a version like this, though,

int c_api(int, va_list arguments)

you can write:

func swiftAPI(_ x: Int, arguments: CVarArg...) -> Int {
  return withVaList(arguments) { c_api(x, $0) }


Adopted By

See Also

C Variadic Functions

func withVaList<R>([CVarArg], (CVaListPointer) -> R)

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

struct CVaListPointer

The corresponding Swift type to va_list in imported C APIs.

func getVaList([CVarArg])

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