IOS对plist配置文件的读写操作

读取:
---------------------------------------------------------------

//首先读取studentInfo.plist中的数据
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"customInfo" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    
//将学生信息填入视图
NSDictionary *tmpInfo = [dictionary objectForKey: @"Student"];
self.stuName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
self.stuSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];
self.stuNum.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Num"]];
    
//将导师信息写入视图
tmpInfo = [dictionary objectForKey: @"Mentor"];
self.mtName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
self.mtSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];

 



全新写入:
---------------------------------------------------------------
NSMutableDictionary *dictplist = [[NSMutableDictionary alloc ] init];
//定义第一个插件的属性
NSMutableDictionary *plugin1 = [[NSMutableDictionary alloc]init];
[plugin1 setObject:@"张三" forKey:@"name1"];
[plugin1 setObject:@"李四" forKey:@"name2"];
//定义第二个插件的属性
NSMutableDictionary *plugin2 = [[NSMutableDictionary alloc]init];
[plugin2 setObject:@"王五" forKey:@"name1"];
[plugin2 setObject:@"赵斌" forKey:@"name2"];
//设置属性值
[dictplist setObject:plugin1 forKey:@"初一班"];
[dictplist setObject:plugin2 forKey:@"初二班"];
//写入文件
[dictplist writeToFile:plistPath atomically:YES];

 

 

//修改某一配置项。

 

//载入配置文件。   
    NSString* plistPath = [NSString stringWithFormat:@"%@/letters.plist",[[Globals getResourceManager] getResPath]];
        
    NSMutableDictionary* dicWrite = [[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath] mutableCopy];
    NSMutableDictionary* dicWLetter = [dicWrite objectForKey:letter];
    NSString* v = alertView.tag == 1 ? @"1" : @"0";
    [dicWLetter setValue:v forKey:@"isOk"];
    [dicWrite setValue:dicWLetter forKey:letter];
    
    [dicWrite writeToFile:plistPath atomically:YES];
    [dicWrite release];
    dicWrite = nil;

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值