一、代码创建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. MySQL binlog_rows_query_log_events

    当binlog_format=statement的时候进制日志只记录的是SQL语句,当binlog_fromat=row的时候记录的是event,如果想要在row模式的情况下 也记录SQL语句:bin ...

  2. OCR中的倾斜矫正

    电面中被问到了做的LPR,简单的介绍了下后又问到了关于如何矫正倾斜角的问题.答得比较含糊,所以今天来补充一下. 倾斜矫正的方法有很多种,包括基于Hough变换的矫正,基于字符投影的倾角矫正,常规线性角 ...

  3. [POJ] 1274 The Perfect Stall(二分图最大匹配)

    题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...

  4. c++ 字符类型总结区别wchar_t,char,WCHAR(转)

    1.区别wchar_t,char,WCHAR ANSI:即 char,可用字符串处理函数:strcat( ),strcpy( ), strlen( )等以str打头的函数.   UNICODE:wch ...

  5. cf C. Dima and Containers

    http://codeforces.com/contest/358/problem/C 将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面.然后模拟就可以了. #inclu ...

  6. Use OWIN to Self-Host ASP.NET Web API 2

      Open Web Interface for .NET (OWIN)在Web服务器和Web应用程序之间建立一个抽象层.OWIN将网页应用程序从网页服务器分离出来,然后将应用程序托管于OWIN的程序 ...

  7. Linux watch 命令

    man watch: WATCH(1) Linux User's Manual WATCH(1) NAME watch - execute a program periodically, showin ...

  8. logstash 利用drop 丢弃过滤日志

    input { stdin { } } filter { grok { match => ["message","\s*%{TIMESTAMP_ISO8601}\s ...

  9. Row Cache Objects

    This latch comes into play when user processes are attempting to access or update the cached data di ...

  10. android开发论坛

    http://www.hiapk.com/ http://bbs.hiapk.com/ http://bbs.gfan.com/ http://bbs.anzhi.com/ http://www.ap ...