iOS中plist的快速生成方法

来源:互联网 发布:卡苏马苏奶酪 知乎 编辑:程序博客网 时间:2024/05/24 02:21

在之前的工作当中,曾经需要配置一个Plist文件,当时傻傻的一条一条输入,耗费了很长的时间.后来公司大神教了一个很好地方法,现在特此记录一下


NSArray *name = [[NSArray alloc]initWithObjects:@"Achafexp",@"Bonkers",@"carolingia",@"catholicschoolgirls",@"Chubsy",@"devroye",@"donreesclaws",@"feenacasual",@"Flakes",@"Gangster",@"gothic_ultra_ot",@"Howardson",@"Husser",@"JustOldFashion",@"Kells_SD",@"Kensinton",@"Kookazoo",@"littlelordfontleroy",@"Mothproof_Script",@"Nuttipy",@"OldSchool",@"oliver",@"Percirk",@"readyformycloseup",@"Reginald",@"SFCollegiateSolid",@"Tangerine_Bold",@"Zainly", nil];    NSLog(@"%d",name.count);        NSMutableArray *all = [[NSMutableArray alloc]initWithCapacity:0];        for (int i = 0; i<28; i++) {        NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:[name objectAtIndex:i],@"font",@"hello",@"text", nil];        [all addObject:dict];    }    NSString *tempPath = NSTemporaryDirectory();NSString *path = [tempPath stringByAppendingPathComponent:@"EnFontPList.plist"];[all writeToFile:path atomically:YES];


//其核心,主要就是NSString *path = [tempPath stringByAppendingPathComponent:@"EnFontPList.plist"];[all writeToFile:path atomically:YES];


atomically参数解释

这个参数意思是如果为YES则保证文件的写入原子性,就是说会先创建一个临时文件,直到文件内容写入成功再导入到目标文件里.

如果为NO,则直接写入目标文件里.

这样就可以生成一个plist,很方便是不是,哈哈~微笑


源码:Plist 动态写入DEMO



                                             
0 0
原创粉丝点击