Converting an UnsafePointer with length to a Swift Array type

后端 未结 2 790
执念已碎
执念已碎 2020-12-16 10:04

I\'m looking for the simplest ways to achieve reasonable C interoperability in Swift, and my current block is converting an UnsafePointer (which was

2条回答
  •  佛祖请我去吃肉
    2020-12-16 10:53

    extension NSData {
    
        public func convertToBytes() -> [UInt8] {
            let count = self.length / sizeof(UInt8)
            var bytesArray = [UInt8](count: count, repeatedValue: 0)
            self.getBytes(&bytesArray, length:count * sizeof(UInt8))
            return bytesArray
        }
    }
    

    You can convert row data to byts (Uint8)

    Copy Extension and use it..

提交回复
热议问题