swift 中 uint8_t 相当于什么?

Sem*_*ush 3 c++ objective-c type-conversion swift

obj-c/c++ 框架中有一个方法,它采用uint8_t和常规int

- (bool)push:(uint8_t *)buf length:(int)len;
Run Code Online (Sandbox Code Playgroud)

我使用桥接文件来访问此方法,但是当我使用UInt8Int快速调用它时,出现以下错误:

无法使用“(UInt8, length: Int)”类型的参数列表调用“push”

我怎样才能让它发挥作用?

Srđ*_*đan 5

该方法需要一个指向类型元素数组的指针UInt8和一个Int32值。你可以这样做:

var buffer: [UInt8] = [0, 1, 2]
yourObject.push(UnsafeMutablePointer<UInt8>(buffer), length: Int32(buffer.count))
Run Code Online (Sandbox Code Playgroud)

在这里查看如何处理指针:https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html