Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 706
Vipin Avatar asked May 25 '11 12:05

Vipin


1 Answers

 const uint8_t *bytes = (const uint8_t*)[myData bytes];
 //                                   ^^ note the asterisk
like image 190
JeremyP Avatar answered Nov 02 '22 00:11

JeremyP