The String to bytes[]
NSString *strData = @"ca 20 fe c1 04 03 03 07 00 ac";
The Result is
UInt8 bytes[]= {0xca,0x20,0xfe,0xc1,0x04,0x03,0x03,0x07,0x01,0xac};
for swift code, how convert to Objective-C
let data = NSString(string : "ca 20 fe c1 04 03 03 07 01 ac"); let dataArr = data.componentsSeparatedByString(" ") var bytes : [UInt8] = []; for item in dataArr { let byte = UInt8(item, radix: 16) bytes.append(byte!); } let hexData = NSData(bytes: bytes, length: 10)