How to create PLIST files programmatically in iphone

I think this post save to .plist properity list will help you if you look through the examples there.

Also, check out Apple's Creating Property Lists Programmatically document for other guidelines and examples.


A PLIST file, also known as a "Property List" file, uses the XML format to store objects such as arrays, dictionaries, and strings.

You can use this code for creating, adding the values and retrieving the values from the plist file.

//Get the documents directory path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"plist.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath: path]) {

    path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"plist.plist"] ];
}

NSMutableDictionary *data;

if ([fileManager fileExistsAtPath: path]) {

    data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
}
else {
    // If the file doesn’t exist, create an empty dictionary
    data = [[NSMutableDictionary alloc] init];
}

//To insert the data into the plist
[data setObject:@"iPhone 6 Plus" forKey:@"value"];
[data writeToFile:path atomically:YES];

//To retrieve the data from the plist
NSMutableDictionary *savedValue = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
NSString *value = [savedValue objectForKey:@"value"];
NSLog(@"%@",value);