简体   繁体   中英

How can i convert NSData to const uint8_t?or getting error while passing a NSData over Wifi

i have a array with two strings:

NSArray *sendingArray = [[NSArray alloc]initWithObjects:@"CAT",@"DOG",nil];

and i converted the array to NSData:

NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:sendingArray];

now i need to convert my NSData(myData) to const uint8_t

i am doing this code to send an array of values through Wifi network.

i send successfully a string over wifi using the below code(my string is "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.

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.

or can any one tell me the way to convert my NSData(myData) to const uint8_t

 const uint8_t *bytes = (const uint8_t*)[myData bytes];
 //                                   ^^ note the asterisk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM