I am using a byte array to开发者_StackOverflow社区 store Nsdata of(4840 bytes) and nnow i have to access the data at index of byte array.here is my code .
[Bufferdata appendBytes:&data length:len];
Byte *byteArray = (Byte *)[data bytes];
for(int i=0;i< sizeof(byteArray);i++)
**NSLog(@"BYTES %@",[byteArray objectAtIndex:i])**;
but it is giving BAD ACCESS
The byteArray
pointer you get back from [data bytes]
is a pointer to raw bytes, not an object pointer. Since it doesn't point to an object, you can't use it to send messages like [byteArray objectAtIndex:i]
. Instead, you should do something like:
for(int i=0;i< sizeof(byteArray);i++)
NSLog(@"BYTES %c", byteArray[i]);
精彩评论