大家好,我是你的好朋友思创斯。今天说一说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];
是否还在为ide开发工具频繁失效而烦恼,来吧关注以下公众号获取最新激活方式。亲测可用!
【正版授权,激活自己账号】:
【官方授权 正版激活】:
//其核心,主要就是 nsstring *path = [temppath stringbyappendingpathcomponent:@"enfontplist.plist"]; [all writetofile:path atomically:yes];
这个参数意思是如果为yes则保证文件的写入原子性,就是说会先创建一个临时文件,直到文件内容写入成功再导入到目标文件里.
如果为no,则直接写入目标文件里.
这样就可以生成一个plist啦,很方便是不是,哈哈~
源码:
文章由思创斯整理,转载请注明出处:https://ispacesoft.com/129762.html