Everything is working fine until I call the saveFile
method (shown below) to write the file back to disk, where it crashes. What am I doing wrong?
This is part of my viewDidLoad
method where I open the file, which works fine.
//Get The Path
[self initPath];
dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:accountsFilePath];
if (accountsArray == nil) {
accountsArray = [[[NSMutableArray alloc]init] autorelease];
}
if (countArray == nil) {
countArray = [[[NSMutableArray alloc]init] autorelease];
}
countArray = [dictionary objectForKey:@"count"];
accountsArray = [dictionary objectForKey:@"username"];
Then I load it into a tableview. I then add some new items to it, which works fine. Then I call this method to save it and it crashes:
-(void)saveFile {
[dictionary setObject:accountsArray forKey:@"username"];
[dictionary setObject:countArray forKey:@"count"];
[dictionary writeToFile:accountsFilePath atomically:YES];
}