一、代码创建plist文件:

  NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

//获取完整路径

NSString *documentsPath = [path objectAtIndex:0];

NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"selectDrugAry.plist"];

以上:如果有这个plist文件,就直接去读取,如果没有这个文件,就直接创建。

二、创建一个数组,也可以是一个词典(关键是看你plist文件里面装的是什么)来存plist里面的数据

NSMutableArray *applist2 = [NSMutableArray arrayWithContentsOfFile:plistPath];

applist2 = [[NSMutableArray alloc]init];

for (int s = 0; s<_selectDrugList.count; s++) {

NSDictionary *dict1= @{

@"formats":[_selectDrugList[s]aryForKey:@"formats"],

@"img":[_selectDrugList[s] strForKey:@"img"],

@"instructions":[_selectDrugList[s] strForKey:@"instructions"],

@"medicineId":[_selectDrugList[s] strForKey:@"medicineId"],

@"medicineName":[_selectDrugList[s] strForKey:@"medicineName"],

@"number":[_selectDrugList[s] strForKey:@"number"],

@"producer":[_selectDrugList[s] strForKey:@"producer"],

@"selected":[_selectDrugList[s] strForKey:@"selected"],

@"shapeName":[_selectDrugList[s] strForKey:@"shapeName"]

};

[applist2 addObject:dict1];

}

[applist2 writeToFile:plistPath atomically:YES];

NSMutableArray *ap2 = [NSMutableArray arrayWithContentsOfFile:plistPath];

NSLog(@"%@",ap2);

问题:为什么我从接口得到的,不能直接写进去呢,非要重新自己手写的,创建内容才可以写进去。有知道的,可以评论解惑。

三、清空plist,我是把我的数组初始化了,然后写到plist里面的

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

//获取完整路径

NSString *documentsPath = [path objectAtIndex:0];

NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"usersListTest.plist"];

NSMutableArray *applist2 = [NSMutableArray arrayWithContentsOfFile:plistPath];

applist2 = [[NSMutableArray alloc]init];

[applist2 writeToFile:plistPath atomically:YES];

四、删除plist文件,请百度,很多的。

关于plist文件的更多相关文章

  1. plist文件、NSUserDefault 对文件进行存储的类、json格式解析

    ========================== 文件操作 ========================== Δ一 .plist文件 .plist文件是一个属性字典数组的一个文件: .plis ...

  2. ios开发之Info.plist文件相关配置

    前言:在iOS开发中有些情况下需要对Info.plist文件进行配置,以下介绍几种相关配置.以后遇到需要配置的再更新... 开发环境:swift3.0.1,Xcode8.1 一,项目中需要使用第三方字 ...

  3. Excel文件转plist文件出现的文件编码问题

    今天在测试时遇到了需要将大量整理好的Excel数据转换为plist文件的情况.百度了一下教程,发现虽然别人也遇到过类似的情况,但是有些讲的还是不够细致.所以做如下整理.   百度到的内容中有使用Mes ...

  4. IOS学习笔记之获取Plist文件读取数据

    @property(nonatomic,strong) NSArray *pic; //创建数组属性 @property(nonatomic,assign) int index; //创建索引属性 @ ...

  5. plist文件的读取和xib加载cell

    plist 文件读取 例如在工程里倒入了plist文件 在工程里需要用到plist文件里的信息,就需要把plist文件读取出来. 如程序: -(NSArray *)moreDataArr{ if (! ...

  6. plist文件

    1.一般可以使用属性列表文件存储NSArray或者NSDictionary之类的数据,这种“属性列表文件”的扩展名是plist,因此也称为“plist文件” 2.接下来通过代码来解析Plist文件中的 ...

  7. Reveal分析IOS界面,plist文件读取

    Reveal分析IOS界面,需要得到app的 softwareVersionBundleId上传到iphone中 , 而IOS8的iTunesMetadata.plist (设备路径/var/mobi ...

  8. plist文件的使用

    什么是plist文件 直接将数据写在代码里面,不是一种合理的做法.如果经常改,就要经常翻开对应的代码进行修改,造成代码扩展性低 因此,可以考虑将经常变的数据放在文件中进行存储,程序启动后从文件中读取最 ...

  9. iOS开发——UI基础-懒加载,plist文件,字典转模型,自定义view

    一.懒加载 只有使用到了商品数组才会创建数组 保证数组只会被创建一次 只要能够保证数组在使用时才创建, 并且只会创建一次, 那么我们就称之为懒加载 lazy - (void)viewDidLoad 控 ...

  10. iOS,plist文件、pct文件,工程设置

    1.使用pch文件 2.在info.plist中配置URL Schemes 3.plist配置拍照界面,复制,粘贴等菜单的显示语言 显示中文 4.使用非ARC库/ARC库 5.链接选项-Objc &a ...

随机推荐

  1. C#高级知识点概要(3) - 特性、自动属性、对象集合初始化器、扩展方法、Lambda表达式和Linq查询

    1.特性(Attributes) 特性(Attributes),MSDN的定义是:公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法 ...

  2. Canvas--2

    Canvas2(关键词:setLineDash .rect .strokeRect .clearRect .arc.sin .strokeText )   绘制其他样式: lineCap 结束端点的设 ...

  3. java开发软件的安装

    jdk+eclipse+svn+maven+mysql+tomcat7.0+sublime安装包和jar插件 配置管理工具-SVN http://download.csdn.net/detail/u0 ...

  4. pendingIntent初步_什么是pendingIntent

    pendingIntent字面意义:等待的,未决定的Intent. 要得到一个pendingIntent对象,使用方法类的静态方法 通过getActivity(Context context, int ...

  5. memcached学习笔记——连接模型

    文章链接:http://www.hcoding.com/?p=121 个人站点:JC&hcoding.com memcached是什么呢?memcached是一个优秀的.高性能的内存缓存工具. ...

  6. uc/os 笔记(转)

    1.uC/OS-II中使用互斥信号对象应该注意 互斥信号对象(Mutual Exclusion Semaphore)简称Mutex,是uC/OS-II的内核对象之一,用于管理那些需要独占访问的资源,并 ...

  7. Kafka笔记--使用ubuntu为bocker(服务器)windows做producer和comsumer(客户端)

    原文连接:http://www.cnblogs.com/davidwang456/p/4201875.html 程序仍然使用之前的一篇博文中的例子 :http://www.cnblogs.com/gn ...

  8. Linux下关闭node应用

    今天在折腾用node接入微信公众号时,碰到了node应用启动后卡死退出,需要找出该进程关闭的问题,由于对shell脚本不是很熟悉,记录如下: 我们在用npm start启动应用后,通常要关闭时,ctr ...

  9. windows上安装winsshd

    winsshd下载地址:http://www.bitvise.com/ssh-server-download 安装后默认配置即可使用:

  10. NOI2011 兔兔与蛋蛋游戏

    http://www.lydsy.com/JudgeOnline/problem.php?id=2437 这道题真是极好的. 75分做法: 搜索. 出题人真的挺良心的,前15个数据点的范围都很小,可以 ...