iOS中plist的快速生成方法

在之前的工作当中,曾经需要配置一个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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值