NSDictionary+plist简单示例

来源:互联网 发布:如何做淘宝联盟淘宝客 编辑:程序博客网 时间:2024/06/05 05:14

在iPhone/iPad工程里面,添加 File->Other->Property List,例如:test.plist,然后在其中添加3個项目(Key) Name, Date, Dept,并填充Value值。

以下为对此test.plist文件的一系列常用操作(myname,mydate,mydept为定义的变量):

NSString *path=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];   //从文件内容创建字典   NSDictionary *dict=[NSDictionary dictionaryWithContentsOfFile:path];   //从字典取出Key对应的Value   self.myname.text=[dict valueForKey:@"Name"] ;   NSLog(@"%@",[dict valueForKey:@"Name"]);   self.mydate.text=[dict valueForKey:@"Date"] ;   self.mydept.text=[dict valueForKey:@"Dept"] ;   //改变Key对应的值   [dict setValue:@"Jimmy" forKey:@"Name"];   //将改变后的结果(字典)写入文件(filepath指定路径和文件名)   [dict writeToFile:filepath atomically:YES];


原创粉丝点击