I'm new to objective c and the problem I'm having is that my "scores.xml" is not overwritten once I try to save it. I have imported the "scores.xml" to my project, but it does not get overwritten once I try to do so. What am I doing wrong? Does anyone have any ideas?
- (void) writeHighScores:(NSString *)PlayerName{
NSString *highscorePath = [[NSString alloc]init];
NSArray * paths = [[NSBundle mainBundle] pathsForResourcesOfType: @".xml" inDirectory:@""];
for ( NSString * path in paths )
{
highscorePath = [path substringToIndex:([path length])];
}
NSMutableArray *arrayFromFile = [NSMutableArray arrayWithContentsOfFile:highscorePath];
for (NSMutableArray *element in arrayFromFile){
if (score > [[element objectAtIndex:1] intValue]){
[element replaceObjectAtIndex:0 withObject:PlayerName];
[element replaceObjectAtIndex:1 withObject:[NSString stringWithFormat:@"%d", score]];
break;
}
}
NSLog(@"Highscore path = %@",highscorePath);
// Write array
[arrayFromFile writeToFile:highscorePath atomically:YES];
}