I want to save some data for my application … I have to save 3 strings and 3 integers
The way I am doing it doesn’t seem ethical and gives error specially on iOS simulator
I am looking for a way that Apple will approve
Will the following code give error on first execution (e.g there is no file or something like that) (load data is called as soon as the app starts )
Here is my code
- (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];
}
I guess something is wrong with my compiler
i made the whole xcode project again copying all the code ans xib files and it Now Works
Cheers and Thanks