A type whose instances can be encoded, and appropriately passed, as elements of a C va_list
.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Overview
You use this protocol to present a native Swift interface to a C “varargs” API. For example, a program can import a C API like the one defined here:
int c_api(int, va_list arguments)
To create a wrapper for the c_api
function, write a function that takes CVar
arguments, and then call the imported C function using the with
function:
func swiftAPI(_ x: Int, arguments: CVarArg...) -> Int {
return withVaList(arguments) { c_api(x, $0) }
}
Swift only imports C variadic functions that use a va_list
for their arguments. C functions that use the ...
syntax for variadic arguments are not imported, and therefore can’t be called using CVar
arguments.
Note
Declaring conformance to the CVar
protocol for types defined outside the standard library is not supported.