-(void) viewDidLoad{[super viewDidLoad];
//读取plist文件
NSString *plistPath=[[NSBundle mainBundle]pathForReaource:@"plistName" ofType:@"plist"];
NSMutableDictionary *data=[NSMutableArray alloc]initWithContentsOfFile:plistPath];
//这样data就是数据了,这样就可以根据字典的操作方法获取确切的数据了,最好的方法是把字典也放到一个array里面这样就可以放更多的数据了也更加有条理。NSLog(@"!@",data);}
把数据存入plist文件中。
- (void)viewDidLoad
{
[super viewDidLoad];
//读取plist
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plistdemo" ofType:@"plist"];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(@"%@", data);
//添加一项内容
[data setObject:@"add some content" forKey:@"c_key"];
//获取应用程序沙盒的Documents目录
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *plistPath1 = [paths objectAtIndex:0];
//得到完整的文件名
NSString *filename=[plistPath1 stringByAppendingPathComponent:@"test.plist"];
//输入写入
[data writeToFile:filename atomically:YES];
//那怎么证明我的数据写入了呢?读出来看看
NSMutableDictionary *data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
NSLog(@"%@", data1);
}