swift Data转string 以及 [bytes]转NSData

data 转string

func string(from data: Data) -> String {
        return String(format: "%@", data as CVarArg)
    }

[bytes]转NSData

let bytes:[UInt8] = [0x07,0x4d,0x45,0x53,0x48,0x31,0x32,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
let data = NSData(bytes: bytes, length: bytes.count)
print(data)

你可能感兴趣的:(swift Data转string 以及 [bytes]转NSData)