Saving a single NSMutableDictionary in a plist
- by yesimarobot
I have one dictionary I need to save into a plist. The paletteDictionary always returns nil:
- (void)saveUserPalette:(id) sender
{
[paletteDictionary setObject:matchedPaletteColor1Array forKey:@"1"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"UserPaletteData.plist"];
// write plist to disk
[paletteDictionary writeToFile:path atomically:YES];
}
I'm reading the data back in a different view like:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"UserPaletteData.plist"];
NSMutableDictionary *plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:path];
if(plistDictionary==nil ){
NSLog(@"failed to retrieve dictionary from disk");
}