我正在开发一个简单的iOS游戏,我的应用程序大小只有3 MB 这是我用来保存用户高分的代码
问题是,每次我使用该应用程序时,其文档和数据文件的大小都会增加。它在我的iPad上达到了28 MB。为什么会这样? 任何帮助表示赞赏 - (void)applicationDidEnterBackground:(UIApplication *)application{
NSArray *value = [[NSArray alloc]initWithObjects:[NSNumber numberWithFloat:easyHighscoreFloat],[NSNumber numberWitFloat:normalHighscoreFloat],[NSNumber numberWithFloat:hardHighscoreFloat],nil];
[value writeToFile:[self saveHighScore] atomically:YES];
}
-(NSString*)saveHighScore{
NSArray *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[filePath objectAtIndex:0]stringByAppendingPathComponent:@"savedState.plist"];
}
- (void)viewDidLoad{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:[UIApplication sharedApplication]];
NSString *path = [self saveHighScore];
BOOL fileExists = [[NSFileManager defaultManager]fileExistsAtPath:path];
if (fileExists) {
NSArray *loadValues = [[NSArray alloc]initWithContentsOfFile:path];
easyHighscoreFloat = [[loadValues objectAtIndex:0]floatValue];
normalHighscoreFloat = [[loadValues objectAtIndex:1]floatValue];
hardHighscoreFloat = [[loadValues objectAtIndex:2]floatValue];
}else{
easyHighscoreFloat = 0;
normalHighscoreFloat = 0;
hardHighscoreFloat = 0;
}
}