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

10,417
 const uint8_t *bytes = (const uint8_t*)[myData bytes];
 //                                   ^^ note the asterisk
Share:
10,417
Vipin
Author by

Vipin

Updated on June 18, 2022

Comments

  • Vipin
    Vipin almost 2 years

    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