Welcome to my iphone development code blog

Welcome to my iphone development code blog
"SIMPLICITY IS BEST PROFESSION"

Thursday, July 15, 2010

how to read and write to plist

we can use the code below

- (void)readPlist
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Contacts.plist"];
listOfItems = [[NSMutableArray alloc] initWithContentsOfFile:path];

}

- (void)writeToPlist
{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Contacts.plist"];

[listOfItems writeToFile:path atomically:YES];

}

No comments:

Post a Comment