我正在使用下面的方法从我的 plist 中获取一个数组,然后将某个值增加 1,然后保存它。但是,我记录了数组,并且该值实际上并没有每次都上升。
在我的 plist 中,我有一个数组,在那个数字值中,每个值都设置为 0。所以每次我再次运行它时,它似乎又回到了 0。
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Words.plist"];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];
NSMutableArray *errors = [dict objectForKey:[NSString stringWithFormat:@"Errors%d.%d", [[stageSelectionTable indexPathForSelectedRow] section] +1, [[stageSelectionTable indexPathForSelectedRow] row] +1]];
int a = [[errors objectAtIndex:wordIndexPath] intValue];
a += 1;
NSNumber *b = [NSNumber numberWithInt:a];
[errors replaceObjectAtIndex:wordIndexPath withObject:b];
[errors writeToFile:finalPath atomically:YES];