我是目标 c 的新手,我遇到的问题是,一旦我尝试保存它,我的“scores.xml”就不会被覆盖。我已将“scores.xml”导入我的项目,但一旦我尝试这样做,它就不会被覆盖。我究竟做错了什么?有没有人有任何想法?
- (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];
}