Use imported C types or call C variadic functions.
C Interoperability
Topics
C and Objective-C Pointers
struct OpaquePointer A wrapper around an opaque C pointer.
struct AutoreleasingUnsafeMutablePointer A mutable pointer-to-ObjC-pointer argument.
C Variadic Functions
func withVaList <R>([CVarArg], (CVaListPointer) -> R) -> R Invokes the given closure with a C va argument derived from the given array of arguments.
struct CVaListPointer A wrapper around a C va pointer.
protocol CVarArg A type whose instances can be encoded, and appropriately passed, as elements of a C va.
func getVaList ([CVarArg]) -> CVaListPointer 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 withUnsafePointer <T, Result>(to: inout T, (UnsafePointer<T>) -> Result) -> Result Invokes the given closure with a pointer to the given argument.
func withUnsafeMutablePointer <T, Result>(to: inout T, (UnsafeMutablePointer<T>) -> Result) -> Result Calls the given closure with a mutable pointer to the given argument.
func withUnsafeBytes <T, Result>(of: inout T, (UnsafeRawBufferPointer) -> Result) -> Result Invokes the given closure with a buffer pointer covering the raw bytes of the given argument.
func withUnsafeMutableBytes <T, Result>(of: inout T, (UnsafeMutableRawBufferPointer) -> 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 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 CLongLong The C ‘long long’ type.
typealias CShortThe C ‘short’ type.
typealias CSignedChar The C ‘signed char’ type.
typealias CUnsignedChar The C ‘unsigned char’ type.
typealias CUnsignedInt The C ‘unsigned int’ type.
typealias CUnsignedLong The C ‘unsigned long’ type.
typealias CUnsignedLongLong The C ‘unsigned long long’ type.
typealias CUnsignedShort The C ‘unsigned short’ type.
typealias CWideChar 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.