adding byte by byte to a NSMutableData object
adding byte by byte to a NSMutableData object
- Subject: adding byte by byte to a NSMutableData object
- From: Ben Dougall <email@hidden>
- Date: Sat, 4 Oct 2003 15:34:22 +0100
is this a way to add bytes? i'm looking for basically the same effect
that appendString has on a NSMutableString object, but for
NSMutableData. and i'd prefer a direct pointer to the data way, like in
c, rather than a method (as the data gets added byte by byte).
- (NSData *) makeNewDataFromOld:(NSData *)oldData
{
unsigned length;
unsigned step = 0;
const unsigned char *od;
unsigned char *nd;
NSMutableData *newData = [[NSMutableData alloc] initWithLength:
[oldData length] ];
od = [oldData bytes];
nd = [newData mutableBytes];
length = [oldData length];
while(os < length) {
*(nd + step) = *(od + step) + 1; // add 1 to each byte (just a
silly example)
step++;
}
[newd autorelease];
return [ NSData dataWithData: newData];
}
i've tried something similar in my code, but a bit more useful, and
it's not working out. not quite sure where it's going wrong at the
moment. is the above a reasonable way to add bytes onto a mutable data
object? if not, how should it be done?
thanks, ben.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.