協議
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。