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
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 } }