Use imported C types or call C variadic functions.
C Interoperability
Topics
C and Objective-C Pointers
struct Opaque Pointer
A wrapper around an opaque C pointer.
struct Autoreleasing Unsafe Mutable Pointer
A mutable pointer-to-ObjC-pointer argument.
C Variadic Functions
func with Va List<R>([CVar Arg], (CVa List Pointer) -> R) -> R
Invokes the given closure with a C va
argument derived from the given array of arguments.
struct CVa List Pointer
A wrapper around a C va
pointer.
protocol CVar Arg
A type whose instances can be encoded, and appropriately passed, as elements of a C va
.
func get Va List([CVar Arg]) -> CVa List Pointer
Returns 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) -> Result
Invokes 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) -> Result
Calls 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) -> Result
Invokes 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) -> Result
Invokes the given closure with a mutable buffer pointer covering the raw bytes of the given argument.
Aliases for Imported C Types
typealias CBool
The C ‘_Bool’ and C++ ‘bool’ type.
typealias CChar
The C ‘char’ type.
typealias CChar16
The C++11 ‘char16_t’ type, which has UTF-16 encoding.
typealias CChar32
The C++11 ‘char32_t’ type, which has UTF-32 encoding.
typealias CDouble
The C ‘double’ type.
typealias CFloat
The C ‘float’ type.
typealias CInt
The C ‘int’ type.
typealias CLong
The C ‘long’ type.
typealias CLong Long
The C ‘long long’ type.
typealias CShort
The C ‘short’ type.
typealias CSigned Char
The C ‘signed char’ type.
typealias CUnsigned Char
The C ‘unsigned char’ type.
typealias CUnsigned Int
The C ‘unsigned int’ type.
typealias CUnsigned Long
The C ‘unsigned long’ type.
typealias CUnsigned Long Long
The C ‘unsigned long long’ type.
typealias CUnsigned Short
The C ‘unsigned short’ type.
typealias CWide Char
The 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.