Use imported C types or call C variadic functions.
C Interoperability
Topics
C and Objective-C Pointers
struct Opaque PointerA wrapper around an opaque C pointer.
struct Autoreleasing Unsafe Mutable PointerA mutable pointer-to-ObjC-pointer argument.
C Variadic Functions
func with Va List<R>([CVar Arg], (CVa List Pointer) -> R) -> RInvokes the given closure with a C va argument derived from the given array of arguments.
struct CVa List PointerA wrapper around a C va pointer.
protocol CVar ArgA type whose instances can be encoded, and appropriately passed, as elements of a C va.
func get Va List([CVar Arg]) -> CVa List PointerReturns a CVa that is backed by autoreleased storage, built from the given array of arguments.
Pointers to Values
Access a pointer to a variable in memory for explicit passing to C functions.
func with Unsafe Pointer<T, Result>(to: inout T, (Unsafe Pointer<T>) -> Result) -> ResultInvokes the given closure with a pointer to the given argument.
func with Unsafe Mutable Pointer<T, Result>(to: inout T, (Unsafe Mutable Pointer<T>) -> Result) -> ResultCalls the given closure with a mutable pointer to the given argument.
func with Unsafe Bytes<T, Result>(of: inout T, (Unsafe Raw Buffer Pointer) -> Result) -> ResultInvokes the given closure with a buffer pointer covering the raw bytes of the given argument.
func with Unsafe Mutable Bytes<T, Result>(of: inout T, (Unsafe Mutable Raw Buffer Pointer) -> Result) -> ResultInvokes the given closure with a mutable buffer pointer covering the raw bytes of the given argument.
Aliases for Imported C Types
typealias CBoolThe C ‘_Bool’ and C++ ‘bool’ type.
typealias CCharThe C ‘char’ type.
typealias CChar16The C++11 ‘char16_t’ type, which has UTF-16 encoding.
typealias CChar32The C++11 ‘char32_t’ type, which has UTF-32 encoding.
typealias CDoubleThe C ‘double’ type.
typealias CFloatThe C ‘float’ type.
typealias CIntThe C ‘int’ type.
typealias CLongThe C ‘long’ type.
typealias CLong LongThe C ‘long long’ type.
typealias CShortThe C ‘short’ type.
typealias CSigned CharThe C ‘signed char’ type.
typealias CUnsigned CharThe C ‘unsigned char’ type.
typealias CUnsigned IntThe C ‘unsigned int’ type.
typealias CUnsigned LongThe C ‘unsigned long’ type.
typealias CUnsigned Long LongThe C ‘unsigned long long’ type.
typealias CUnsigned ShortThe C ‘unsigned short’ type.
typealias CWide CharThe C++ ‘wchar_t’ type.
See Also
Programming Tasks
Print values to the console, read from and write to text streams, and use command line arguments.
Fortify your code with runtime checks, and examine your values' runtime representation.
Use key-path expressions to access properties dynamically.
Allocate and manage memory manually.
Perform casts between types or represent values of any type.
Work with prefix, postfix, and infix operators.