Install Theme

Your web-browser is very outdated, and as such, this website may not display properly. Please consider upgrading to a modern, faster and more secure browser. Click here to do so.

Hexa's Developments

Posts tagged objective c

Feb 16 '12

Saving to Plist in format key(with name) - value(dictionary)

If added only an array, the plist will create Item0, Item1 …

With some coding, it’ll save in a format you desire.

Get Path of Plist

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@”CurrencyISO.plist”];

Setting Up the Array to store the Dic

        [dataArray addObject: [[NSMutableDictionary alloc]
                               initWithObjectsAndKeys:
                               [countryISO objectAtIndex:i], @”Prefix”,
                               @”0”, @”Index”,
                               nil]];

Creating a Dictionary of your choice

        [countryDic setValue: [dataArray objectAtIndex:i] forKey:mainKey];

Writing to the PLIST!
        [countryDic writeToFile:plistPath atomically:YES];   

Note: All these are inside a for loop.

Tags: xcode iphone plist array mutable dictionary cocoa objective c