Hello,
I'm having trouble with the following code. Basically the code is meant to open the text file put the contents into a string then put the lines in a globally accessible array. I don't get any errors, I just get nothing. When I step through the code using the debugger filestring is nill even after the stringWithContentsOfFile method is called. I'm not even sure if this is the best way to put the contents of a file into an array, but it seems to make sense. perhaps not...
// in header
NSArray *wordlist; //declare array
//in init method
wordlist = [[NSArray alloc] init]; // init array
// import word list from a file
NSMutableString *fileString; // declare string
fileString = [NSMutableString stringWithCapacity:0]; // init string
[fileString retain]; // bump up retain count
fileString = [NSMutableString stringWithContentsOfFile:@"wordlist.txt"]; // reads file into memory as an NSMutableString
wordlist = [fileString componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings
[fileString release]; // release string