在swift中,uint8_t的等效物是什么?

What is the equivalent of uint8_t in swift?

本文关键字:是什么 swift uint8      更新时间:2023-10-16

在obj-c/c++框架中有一个方法,它接受uint8_t和常规int:

- (bool)push:(uint8_t *)buf length:(int)len;

我使用了一个桥接文件来访问这个方法,但是当我使用UInt8Int在swift中调用它时,我得到以下错误:

不能用类型为'(UInt8, length: Int)'的参数列表调用'push'

我怎样才能使它工作?

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

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

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