NSData to [Uint8] in Swift

后端 未结 7 810
无人及你
无人及你 2020-12-04 17:24

I couldn\'t find a solution to this problem in Swift (all of them are Objective-C, and they deal with pointers which I don\'t think exist in Swift in the same form). Is ther

7条回答
  •  悲哀的现实
    2020-12-04 17:58

    You can try

    extension Data {
    func toByteArray() -> [UInt8]? {
        var byteData = [UInt8](repeating:0, count: self.count)
        self.copyBytes(to: &byteData, count: self.count)
        return byteData
      }
    }
    

提交回复
热议问题