アプリケーション用にいくつかのデータを保存したい... 3 つの文字列と 3 つの整数を保存する必要がある
私がやっている方法は倫理的ではないようで、特にiOSシミュレーターでエラーが発生します
Appleが承認する方法を探しています
次のコードは最初の実行でエラーになりますか (たとえば、ファイルがないなど) (アプリが起動するとすぐにロード データが呼び出されます)。
これが私のコードです
- (NSString *) saveFilePath{
NSArray *path =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[path objectAtIndex:0] stringByAppendingPathComponent:@"savefile.plist"];
}
-(void)loadData:(int)a{
NSString *myPath = [self saveFilePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
if (fileExists) {
NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
NSString *myString;
myString=[NSString stringWithFormat:@"%@`s : %@ Taps",[values objectAtIndex:(a++)],[values objectAtIndex:a]];
label.text=myString;
hscore=[[values objectAtIndex:a] integerValue];
}
}
-(void)saveData:(int)a{
NSArray *values=[[NSArray alloc] initWithObjects:@"No Game",@"0",@"No Game",@"0",@"No Game",@"0", nil];
NSString *myPath = [self saveFilePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
if (fileExists) {
values = [[NSArray alloc] initWithContentsOfFile:myPath];
}
// some value changing logic that works
[values writeToFile:myPath atomically:YES];
}