Saving a single NSMutableDictionary in a plist

Posted by yesimarobot on Stack Overflow See other posts from Stack Overflow or by yesimarobot
Published on 2010-03-11T04:09:28Z Indexed on 2010/03/11 4:39 UTC
Read the original article Hit count: 593

Filed under:
|
|

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");
}

© Stack Overflow or respective owner

Related posts about plist

Related posts about iphone