I'm creating 2 plist files in my documents directoy which I'd like to use for storing arrays. On the first run, while the files arent created yet everything works fine, items get saved into the arrays and then get written to one of the plist files I can check this in the documents dir. But when I have to read from the plist and then use it I get an EXC_BAD_ACCESS error. I have the following code:
in viewDidLoad:
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSString *arrayPath = [documentsDirectory stringByAppendingPathComponent:@"Save1.plist"];
NSString *arrayPath2 = [documentsDirectory stringByAppendingPathComponent:@"Save2.plist"];
NSFileManager *fManager = [NSFileManager defaultManager];
if([fManager fileExistsAtPath:arrayPath] && [fManager fileExistsAtPath:arrayPath2]) {
saveArray1 = [[NSMutableArray alloc] initWithContentsOfFile:arrayPath];
saveArray2 = [[NSMutableArray alloc] initWithContentsOfFile:arrayPath2];
}
else {
saveArray1 = [[NSMutableArray alloc] init];
saveArray2 = [[NSMutableArray alloc] init];
}
And later I have
[saveArray addObject:something];
[sav开发者_如何学GoeArray2 addObject:something2];
[saveArray1 writeToFile:arrayPath atomically:YES];
[saveArray2 writeToFile:arrayPath2 atomically:YES];
It should be [saveArray1 addObject:something];
not [saveArray addObject:something];
精彩评论