协议
CVar
CVarArg
一种类型,其实例可以作为 C
va_list
的元素进行编码和适当传递。声明
protocol CVarArg
概述
您使用此协议向 C“varargs” API 提供本机 Swift 接口。例如,一个程序可以像这里定义的那样导入一个 C API:
int c_api(int, va_list arguments)
要为 c_api
函数创建包装器,请编写一个接受 CVarArg
参数的函数,然后使用 withVaList(_:_:)
函数调用导入的 C 函数:
func swiftAPI(_ x: Int, arguments: CVarArg...) -> Int {
return withVaList(arguments) { c_api(x, $0) }
}
Swift 只导入使用 va_list
作为参数的 C 可变参数函数。不导入对可变参数使用 ...
语法的 C 函数,因此不能使用 CVarArg
参数调用。
如果您需要将可选指针作为 CVarArg
参数传递,请使用 Int(bitPattern:)
初始化程序将可选指针解释为 Int
值,它与所有支持的平台上的指针具有相同的 C 可变参数调用约定。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift CollectionDifference firstIndex(of:)用法及代码示例
- Swift Collection prefix(upTo:)用法及代码示例
- Swift ContiguousArray forEach(_:)用法及代码示例
- Swift CollectionOfOne contains(_:)用法及代码示例
- Swift ClosedRange.Index ..<(_:)用法及代码示例
- Swift Collection first用法及代码示例
- Swift Character lowercased()用法及代码示例
- Swift ContiguousArray insert(contentsOf:at:)用法及代码示例
- Swift ClosedRange index(_:offsetBy:)用法及代码示例
- Swift CollectionOfOne compactMap(_:)用法及代码示例
- Swift CollectionDifference contains(where:)用法及代码示例
- Swift CollectionOfOne last(where:)用法及代码示例
- Swift Collection dropLast(_:)用法及代码示例
- Swift ContiguousArray reserveCapacity(_:)用法及代码示例
- Swift Comparable ...(_:)用法及代码示例
- Swift ClosedRange.Index ..<(_:_:)用法及代码示例
- Swift ContiguousArray lexicographicallyPrecedes(_:)用法及代码示例
- Swift ContiguousArray elementsEqual(_:)用法及代码示例
- Swift ContiguousArray isEmpty用法及代码示例
- Swift ContiguousArray suffix(from:)用法及代码示例
- Swift CollectionDifference forEach(_:)用法及代码示例
- Swift CollectionDifference firstIndex(where:)用法及代码示例
- Swift CollectionDifference prefix(_:)用法及代码示例
- Swift CollectionOfOne firstIndex(of:)用法及代码示例
- Swift CollectionDifference randomElement()用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 CVarArg。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。