在iOS中保存简单的值会产生一个大的文档和数据文件

在iOS中保存简单的值会产生一个大的文档和数据文件,ios,nsdocumentdirectory,Ios,Nsdocumentdirectory,我正在开发一个简单的iOS游戏,我的应用程序大小只有3MB 这是我用来保存用户高分的代码 问题是每次我使用这个应用程序,它的文档和数据文件都会增加。在我的iPad上达到了28MB。为什么会这样? 谢谢你的帮助 - (void)applicationDidEnterBackground:(UIApplication *)application{ NSArray *value = [[NSArray alloc]initWithObjects:[NSNumber numberWithFlo

我正在开发一个简单的iOS游戏,我的应用程序大小只有3MB 这是我用来保存用户高分的代码

问题是每次我使用这个应用程序,它的文档和数据文件都会增加。在我的iPad上达到了28MB。为什么会这样? 谢谢你的帮助

     - (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;
    }
}

大文件中的数据是什么样子的?有没有办法查看此文件?。我只知道它有多大,从设置应用程序(设置->常规->使用)运行模拟器上的应用程序。然后转到/Library/Application Support/iPhone模拟器//应用程序//文档。由于您将文件存储在Documents目录中,您应该能够在我提到的路径中看到该文件,您可以打开它以检查内容。我只是按照您的建议做了,我在plist文件中找到了我保存的值,它的大小只有355字节!也许问题不在于上面的代码块,为什么设置应用程序中显示的我的应用程序的文档和数据超过20MB,这会发生在每个人身上吗?