Quantcast
Channel: snippet Feed
Viewing all articles
Browse latest Browse all 29

How to save an NSArray into Plist with a Key?

$
0
0

Saving an NSArray with a Key into PList is easy. You can start with a NSMutableDictionary and add each array as an entry with a key. Finally save into file.

+(void) saveArrayIntoPlist:(NSArray*)aArray withKey:(NSString*)arrayKey {
   
    CCLOG(@"savePhotoIdArrayToDoc");
    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filePath = [NSStringstringWithFormat:@"%@/info.plist", docDir];
   
    NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
   
    if (info != nil) {    
        [info setObject:aArray forKey:arrayKey];
        [info writeToFile:filePath atomically:YES];
        [info release];
    }
    else {
        info = [NSDictionarydictionaryWithObject:aArray forKey:arrayKey];
        [info writeToFile:filePath atomically:YES];
    }


Viewing all articles
Browse latest Browse all 29

Trending Articles