• 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: append to file (new to Cocoa)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: append to file (new to Cocoa)


  • Subject: Re: append to file (new to Cocoa)
  • From: j o a r <email@hidden>
  • Date: Fri, 8 Jul 2005 16:38:26 +0200


On 8 jul 2005, at 10.50, Ron Fleckner wrote:

After searching the docs and the list archive, I haven't been able to find out how to append data (text in my case) to a file. I'm making a fairly simple game and want to allow users to keep a record of their scores. This is my workaround:

// write new data to 'scores' file
NSString *theNewScore = [NSString stringWithFormat:@"%d\n", aInt];
NSError *err;
NSString *fileContents = [NSString stringWithContentsOfFile:pathToFile];
NSString *newFileContents = [fileContents stringByAppendingString:theNewScore];
[newFileContents writeToFile:pathToFile atomically:YES encoding:NSASCIIStringEncoding error:&err];


but is there a way I can simply append the text without first reading the whole file into a NSString variable and then using stringByAppendingString?

You might also want to have a look at NSUserDefaults. If its only a little data, like a list of highest scores, it would certainly do just fine - and you wouldn't have to deal with any file management at all.


j o a r



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: 
 >append to file (new to Cocoa) (From: Ron Fleckner <email@hidden>)

  • Prev by Date: Re: append to file (new to Cocoa)
  • Next by Date: Link error: zerolink
  • Previous by thread: Re: append to file (new to Cocoa)
  • Next by thread: Re: append to file (new to Cocoa)
  • Index(es):
    • Date
    • Thread