Breaking News
Home / iOS / iOS Snippets / How to save an NSArray into Plist with a Key?

How to save an NSArray into Plist with a Key?

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 {
    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];


Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Leave a Reply