I am using xcode 4 to compile this application.
I am building a space game. To store my highscore values (which in this case is represented by an int, _totalSeconds), I made an array which I write to a file. Whenever the character "dies", his highscores is retrieved from the file as an array, added to the array, and written back into the file. I then call this in the highscore page of my app and use some sorting methods. However, this part is irrelevent. The problem is that after the user "dies", his highscore doesn't appear to be saved to the array. Here is my code block that comes into play after the user "dies" (by the way, this is the only code that creates this file, could it be that this file that I am calling hasn't been created yet? If so, how do I create it?):
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSNumber *highscore = [[NSNumber alloc] initWithInteger:_totalSeconds];
NSString *choice = [NSString stringWithFormat:@"%@/userschoice", documentsDirectory];
NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:choice];
[array addObject:highscore];
int test = [array count];
NSLog(@" %d",test);
[array writeToFile:choice atomically:YES];
[newText release];
The console says that [array count] = 0. I am very confused. Also, as a side-note, this app runs flawlessly in Xcode 3 (where it originated from). If you need any other information, please comment.