I have a main dictionary where each entry is a dictionary. I need to save this on a plist and then get its contents.
This is what I do to save the dictionary
NSMutableDictionary *fruit = [[NSMutableDictionary alloc] init];
[fruit setObject:quantity forKey:@"quantity"];
[fruit setObject:productID forKey:@"productID"];
[fruit setObject:nameID forKey:@"nameID"];
NSMutableDictionary *stock = [[NSMutableDictionary alloc] init];
[stock setObject:fruit forKey:@"nameID"];
... after adding all the fruits to the stock dictionary, write the stock on plist
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"stock.plist"];
NSMutableDictionary *stock = [NSMutableDictionary dictionaryWithContentsOfFile:path];
[stock writeToFile:path atomically:YES];
... to restore the dictionary, I use
NSMutableDictionary *stock = [NSMutableDictionary dictionaryWithContentsOfFile:path];
... but it doesnβt save anything in the file ... what am I missing?
Thanks for any help.
source
share