可以先在工程中直接新建一个plist文件,往里面写入自己需要的数据。但是这里的plist文件我们无法修改,是只读的,我们可以将这个plist文件复制一份到沙盒中,然后对沙盒中的文件进行操作。具体代码如下:

从自己建立的plist文件 复制到沙盒中 :

//先获得沙盒路径

NSArray *storeFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *doucumentsDirectiory = [storeFilePath objectAtIndex:0];
        NSString *plistPath =[doucumentsDirectiory stringByAppendingPathComponent:@"myfile.plist"];//假设创建的plist文件名为myfile.plist

//创建文件管理对象,将工程中的plist文件复制到沙盒中,方法一:
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *bundle = [[NSBundle mainBundle] pathForResource:@"myfile" ofType:@"plist"];
        [fileManager copyItemAtPath:bundle toPath:plistPath error:nil];

//方法二:

NSString *path = [[NSBundle mainBundle] pathForResource:@"myfile"ofType:@"plist"];
        NSMutableDictionary *activityDics = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
        [activityDics writeToFile:plistPath atomically:YES];

//判断沙盒中是否存在相应的plist文件,如果不存在就创建
       NSFileManager *fileManager = [NSFileManager defaultManager];
       if( [fileManager fileExistsAtPath:plistPath]== NO ) {
            NSLog(@"not exists");
                 return NO;
            }else{
                return YES;
      }

最新文章

  1. Photoshop和WPF双剑配合,打造炫酷个性的进度条控件
  2. 创建 sequence
  3. Mac上搭建直播服务器Nginx+rtmp
  4. struts2视频学习笔记 19-20(手工编写代码实现所有方法和指定方法校验)
  5. 北邮新生排位赛1解题报告d-e
  6. JavaScript事件处理的三种方式(转)
  7. 【字符串处理】HDOJ-1020-Encoding
  8. ZooKeeper(3.4.5) - 使用 Curator(2.7.0) 监听事件
  9. keystone系列二:keystone源码分析
  10. 深刻认识shift_ram IP core——图像处理学习笔记
  11. shell基本语法
  12. JS 清除DOM 中空白元素节点
  13. happens-before俗解
  14. 八皇后问题-dfs
  15. ES6学习--Object.assign()
  16. 更快的速度、更好的服务——易普优APS云排程
  17. Android中三种超实用的滑屏方式汇总(转载)
  18. Java实习一
  19. replace()函数用法
  20. 【深入理解JAVA虚拟机】第三部分.虚拟机执行子系统.1.类文件结构

热门文章

  1. maven 启动 报错 Fatal error compiling: 无效的目标发行版
  2. python语法笔记(六)
  3. mysql 截断
  4. phalcon: 过滤(Phalcon\Filter())
  5. 最大似然估计(Maximum Likelihood,ML)
  6. typedef void (*funcptr)(void)
  7. 【bzoj1023】仙人掌图
  8. uva-----11292 The Dragon of Loowater
  9. 初学java之面板布局的控制
  10. 接口(C# 参考)