• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
adding byte by byte to a NSMutableData object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: adding byte by byte to a NSMutableData object
      • From: Dustin Voss <email@hidden>
  • Prev by Date: Enumerating problems
  • Next by Date: Re: Enumerating problems
  • Previous by thread: Re: Enumerating problems
  • Next by thread: Re: adding byte by byte to a NSMutableData object
  • Index(es):
    • Date
    • Thread