append to file (new to Cocoa)
append to file (new to Cocoa)
- Subject: append to file (new to Cocoa)
- From: Ron Fleckner <email@hidden>
- Date: Fri, 8 Jul 2005 18:50:44 +1000
Hi list,
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?
TIA for any pointers.
Ron
_______________________________________________
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