i have a array with two strings:
我有一个有两个字符串的数组:
NSArray *sendingArray = [[NSArray alloc]initWithObjects:@"CAT",@"DOG",nil];
and i converted the array to NSData:
我将数组转换为NSData
NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:sendingArray];
now i need to convert my NSData(myData)
to const uint8_t
现在我需要将我的NSData(myData)转换为const uint8_t。
i am doing this code to send an array of values through Wifi network.
我做这个代码是为了通过Wifi网络发送一个值数组。
i send successfully a string over wifi using the below code(my string is "string").
我使用下面的代码通过wifi成功发送了一个字符串(我的字符串是“string”)。
const uint8_t *message = (const uint8_t *)[string UTF8String];
[_outStream write:bytes maxLength:len];
i wrote the below code to send NSData object but it got error.
我写了下面的代码来发送NSData对象,但是它出错了。
code is:
代码是:
const uint8_t *bytes = (uint8_t)[myData bytes];//this line getting error.
[_outStream write:bytes maxLength:len];
can i send my NSData(myData)
through the above method without converting it to const uint8_t? if yes,please give me the code that i need to write.
我可以通过上面的方法发送NSData(myData)而不将其转换为const uint8_t吗?如果是,请给我需要写的代码。
or can any one tell me the way to convert my NSData(myData)
to const uint8_t
或者谁能告诉我如何将NSData(myData)转换为const uint8_t
1 个解决方案
#1
19
const uint8_t *bytes = (const uint8_t*)[myData bytes];
// ^^ note the asterisk
#1
19
const uint8_t *bytes = (const uint8_t*)[myData bytes];
// ^^ note the asterisk