How to save a value in a plist file in iphone?
Posted
by Warrior
on Stack Overflow
See other posts from Stack Overflow
or by Warrior
Published on 2010-04-12T11:07:41Z
Indexed on
2010/04/12
11:13 UTC
Read the original article
Hit count: 311
I am new to iphone development.I am using the below code to add the value to the plist but when check the plist after executing the code i dont see any value saved in the plist.Where do i go wrong? please help me out.The plist i have created is in the resource folder.Thanks.
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
[plistDict setValue:@"hello" forKey:@"choice"];
[plistDict writeToFile:finalPath atomically: YES];
For retrieving the value
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
NSString *value;
value = [plistDict objectForKey:@"choice"];
NSLog(@"the value is %@",value);
It gives only null value.Please help me out.Thanks.
© Stack Overflow or respective owner