• 关于plist文件


    一、代码创建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文件,请百度,很多的。

    做一个有心的女人 比做一个有心机的女人强!
  • 相关阅读:
    核心容器的两个接口(ApplicationContext和BeanFactory)引发出的问题
    ApplicationContext的三个常用实现类:
    IDEA如何找到接口的实现类
    编写BeanFactory
    9.4 Binder系统_驱动情景分析_服务使用过程
    9.3 Binder系统_驱动情景分析_服务获取过程
    9.2 Binder系统_驱动情景分析_服务注册过程
    9.1 Binder系统_C程序示例_框架分析和编写程序
    8.6 Android灯光系统_源码分析_背光灯
    8.5 Android灯光系统_源码分析_通知灯
  • 原文地址:https://www.cnblogs.com/LongLianChuan/p/5113667.html
Copyright © 2020-2023  润新知