获取沙盒文件夹路径的几个方法

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 
 5 @end
 6 
 7 @implementation ViewController
 8 
 9 - (void)viewDidLoad {
10     [super viewDidLoad];
11 
12 #pragma mark - 第一种打开应用程序沙盒路径的方式
13     
14     // 地址是一个字符串
15     // NSSearchPathForDirectoriesInDomains:查找沙盒路径的函数,返回值是一个数组,这个数组里面只有一个元素,这个元素就是路径,直接使用下标取出即可
16     // 第一个参数:枚举值,枚举你具体要查找的文件夹(要进入哪个文件夹直接修改其枚举值即可【NSSearchPathDirectory:进入Document文件夹】)
17     // 第二个参数:NSUserDomainMask表示用户的主目录
18     // 第三个参数:一般设置为YES表示展示完整的路径
19     
20     // 进入Documents文件夹
21     NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
22     
23     NSLog(@"documentPath = %@", documentPath);
24     
25     
26     // 进入Caches文件夹
27     NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
28     
29     NSLog(@"cachesPath = %@", cachesPath);
30     
31 
32 #pragma mark - 第二种打开应用程序沙盒路径的方式
33     
34     // 第一步:先找到主目录文件夹
35     NSString *homePath = NSHomeDirectory();
36     NSLog(@"homePath = %@", homePath);
37     
38     // 第二步:然后拼接自己想进入的文件夹名称
39     NSString *documentPathTwo = [homePath stringByAppendingPathComponent:@"Documents"];
40     NSLog(@"documentPathTwo = %@", documentPathTwo);
41     
42     
43     // 进入Library里面的Caches
44     NSString *libraryPathTwo = [homePath stringByAppendingPathComponent:@"Library/Caches"];
45     NSLog(@"libraryPathTwo = %@", libraryPathTwo);
46     
47 
48 #pragma mark - 特殊的文件夹的查找方式
49     
50     NSString *tmpPath = NSTemporaryDirectory();
51     NSLog(@"tmpPath = %@", tmpPath);
52     
53 }
54 
55 @end

 

转载于:https://www.cnblogs.com/zhizunbao/p/5456234.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值