您的位置:首页 > 其它

一件小事,写Plist

2014-08-11 11:55 197 查看
今天项目中遇到了想将已有的一个plist文件的key、value互换,从新写入一个新的plist文件。代码如下    

//读取本地的old.plist文件
NSDictionary * facDic=[NSDictionary
dictionaryWithContentsOfFile:[[NSBundle
mainBundle] pathForResource:@"old"
ofType:@"plist"]];

//新建可变字典存储值
NSMutableDictionary *tempDic=[[NSMutableDictionary 
alloc]init];
for (NSString *key
in [old
allKeys]) {
     [tempDic
setValue:key forKey:old[key]];
}

//给出写入的新的plist文件的路径,写入new.plist
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSMutableString * path = [paths
objectAtIndex:0];

//得到完整的文件名
NSString *filename=[path
stringByAppendingPathComponent:@"new.plist"];
[tempDic writeToFile:filename
atomically:YES];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  1