• 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
Re: NSMutableData: Adding One char to a NSMutableData Object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableData: Adding One char to a NSMutableData Object


  • Subject: Re: NSMutableData: Adding One char to a NSMutableData Object
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 14 Jan 2006 09:23:55 -0800


On Jan 14, 2006, at 9:12 AM, Jordan Evans wrote:

How do I add one character at a time to a
NSMutableData object?

This code is supposed to be adding an 'a' to a
NSMutableData object, then incrementing it to 'b' and
then adding it, etc., on through the alphabet.  Of
course this snippet doesn't work, and that's why I'm
asking how this is done.  Can anyone help me with
NSData abc's?

        int i;
	unsigned char str[2];
	unsigned char *aBuffer;
        char a = 'a';

	aBuffer = str;

	for( i=0; i<26; i++ )
	{
		str[0] = a++;
		str[1] = '\0';

		[myData appendBytes:aBuffer length:1];
		[myFile writeData:myData];
	}

Does myData actually exist (not nil)? How are you creating it?

Why are you writing to your file after every modification of myData? Just build up myData then write it out once.

How about the following (written in Mail.app not compiled)...

	char a;
	for( a = 'a'; a != 'z'; a++ ) {
		char character = a;
		[myData appendBytes:&character length:sizeof(character)];
	}
	[myFile writeData:myData];

-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSMutableData: Adding One char to a NSMutableData Object (From: Jordan Evans <email@hidden>)

  • Prev by Date: NSMutableData: Adding One char to a NSMutableData Object
  • Next by Date: Re: Endian-ness of "PkgInfo" file
  • Previous by thread: NSMutableData: Adding One char to a NSMutableData Object
  • Next by thread: NSURLProtocol and custom URL scheme
  • Index(es):
    • Date
    • Thread