step !: copy Plist file ,main bundle into document folder
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"DocList.plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Doclist" ofType:@"plist"];
[[NSFileManager defaultManager] copyItemAtPath:bundle toPath:plistPath error:nil];
}
2:Save Value To pList
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"DocList.plist"];
NSMutableArray *savedStock = [NSMutableArray arrayWithContentsOfFile:plistPath];
if(savedStock == nil)
{
savedStock = [[NSMutableArray alloc]initWithCapacity:0];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithCapacity:0];
[data setObject:fileName forKey:@"docname"];
[data setObject:@"Enter the keyword" forKey:@"keyword"];
[data setObject:@"Email Address" forKey:@"f1"];
[data setObject:@"Chat Screen Name" forKey:@"f2"];
[savedStock addObject:data];
[savedStock writeToFile:plistPath atomically:YES];
[data release];
3:Get all Value from plist
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"DocList.plist"];
NSMutableArray *savedStock = [[NSMutableArray alloc] initWithContentsOfFile: plistPath];
for (int i=0 ; i <[savedStock count]; i++)
{
NSLog(@"value %@",[[savedStock objectAtIndex:i] valueForKey:@"docname"]);
NSLog(@"value %@",[[savedStock objectAtIndex:i] valueForKey:@"keyword"]);
}
4:Structure is like:
5:enjoy coding
0 comments:
Post a Comment