Home > DeveloperSection > Forums > Converting data of NSData into bytes array in iOS
Brad Pitt
Brad Pitt

Total Post:61

Posted on    November-20-2015 12:49 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 688  View(s)
Rate this:

I have getting problem with conversion of NSData into bytes array.
this is the code that I am using:

NSData *myData = [NSData dataWithContentsOfFile:pathOfFile];
int dataLength = [myData length];
Byte byteData[dataLength];
byteData = [myData bytes];

My last line generating error 'incompatible types in assignment'.
Can anyone tell me the correct way to do it.

Tarun Kumar

Total Post:214

Posted on    November-20-2015 10:20 PM

The error occurs because I think you are trying to set an allocated array when the return type is pointer.
Use this to allocate data getBytes:length:  call it like this:

[data getBytes:&byteData length:len];

Now, your allocated array is fills the data from the NSData object.

Modified On Nov-20-2015 10:40:43 PM

Don't want to miss updates? Please click the below button!

Follow MindStick