In Objective-C I use the following code to
Convert an Int variable into NSData, a packet of bytes.
Int
NSData
int myScore = 0; NS
For any integer type:
extension FixedWidthInteger { var data: Data { let data = withUnsafeBytes(of: self) { Data($0) } return data } }
Example:
let data = 1.data