merge many bytes arrays into one byte array in objective c -
i have used nsmutabledata merge byte arrays
nsmutabledata *payload; payload = [[nsmutabledata alloc] init]; [payload appendbytes:cfbridgingretain((cm.msgbytes)) length:[cm.msgbytes length]]; nsstring *cmdata = [[nsstring alloc] initwithdata:[payload mutablebytes] encoding:nsutf8stringencoding]; i want keep on adding payload until done
cmdata nil
as initwithdata takes nsdata converted bytes nsdata result still same
nsdata *bytesdata = [nsdata datawithbytes:[payload mutablebytes] length:[payload length]]; nsstring *cmdata = [[nsstring alloc] initwithdata:bytesdata encoding:nsutf8stringencoding];
i think you're confusing things in several places. api says "bytes", it's talking c array of bytes; says "data", it's talking nsdata object.
assuming cm.msgbytes nsdata object, appears given retrieve .length, better version of code be:
nsmutabledata *payload; payload = [[nsmutabledata alloc] init]; [payload appenddata:cm.msgbytes]; nsstring *cmdata = [[nsstring alloc] initwithdata:payload encoding:nsutf8stringencoding]; if wrote class cm belongs to, should rename msgbytes msgdata (or messagedata), match apis better.
Comments
Post a Comment