Okay, Reading and writing data was something I made a big deal out of. Mainly because I started out with C# two years ago. In C#, you have to declare a StreamReader or a StreamWriter. After which, you then give it a location of a file and it returns a string based on the current line you are on. This made since once I figured it out. Then I got a mac a year back and wanted to figure out how to do the same in Objective-C. I tried the hardest method first thinking it was the easiest. You would think that you would do the same in Objective-C that you do in C#. Not so! All the work has been done for you!
Most objects which contain a NS at the beginning of the name have a method called writeToFile:(NSString *)aLocation.
And if they contain a writeToFile, they also contain a initWithContentsOfFile:(NSString *)aLocation.
So, with that said, this is how you will read in a file to a String.
NSString *filesContent = [[NSString alloc] initWithContentsOfFile:@"file.txt"];
To write a string to a file, well, That's easy too.
Another thing I found to be the most useful in Objective-C is that when you write an array to a file, it converts it over to XML. If you have an array of objects, it will convert those objects to XML and put them in the list as well. This is great especially if you are creating a Mac and Windows app that you need to have working together. You can have your windows app conform to the mac's xml standard for writing arrays and you have two applications working on two systems that work off the same file format.
It is also wonderful because there is hardly any code needed to make it read and write data.
Apple has done it better again! :-)