IOS沙盒路径

Xcode 7 的沙盒路径为:

模拟器沙盒路径:

/Users/a625/Library/Developer/CoreSimulator/Devices/2CFF7AE1-CDA8-444D-AAA6-2D51C6FF31EA/data/Containers/Data/Application/9DFC4962-0D8E-4ADE-9803-D0B707E6ACDC/Documents

1.获取沙盒路径的根路径:

//     获取沙盒的根路径
    NSString *home = NSHomeDirectory();
2.拼接路径 :推荐第三种方式,呵呵

//     拼接Documents路径
    1.NSString *docPath = [home stringByAppendingString:@"/Documents"];
    2.NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];<pre name="code" class="objc">/**
     *  NSDocumentDirectory : 查找Documents文件夹
        NSUserDomainMask : 在用户的应用程序下查找
     YES 把路径展开 NO 当前应用的根路径 == ~ 
     NO  ~/Documents

     */
    3.NSString *docPath =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSLog(@"%@",docPath);

 3.拼接文件路径 
// 拼接文件路径
    NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"];
4.向该路径中存入数据就OK了

// 只有具备writeToFile:的对象才能使用plist存储,NSArray
    NSArray *array = @[@1,@2,@"123"];
    
    [array writeToFile:filePath atomically:YES];

这个时候就可以前往文章前面的那个文件夹下看到新建的plist文件了,并且可以打开看到里面的arry数组的数据了,over


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值