SandBox沙盒

沙盒:应用程序之间互相隔离

应用程序只能访问自己本地的内容,不能访问其他app文件目录(越狱手机除外)

为应用程序有自己的缓存和备份数据

写法:NSString* homeDirectory = NSHomeDrirectory();

NSString* appPath = [[NSBundle mainBundle]bundlePath];

1.获得沙盒文件中的文件

项目中的资源文件,会打包到沙盒中,比如plist文件、图片资源(),或者加载xib中的文件

如获得XXX.plist文件的路径

NSBundle bundle = [NSBundle mainBundle];

NSString* plistPath = [bundle pathForResource:@"XXX"ofType:"plist"];

plistPath中包含了对应文件路径的字符串。

2.加载xxx.xib对象

NSBundle bundle = [NSBundle mainBundle];

NSArray * objs = [bundle loadNibName:@"singleView"owner:nil options:nil];

objs就包含了xib中所有的文件对象。

原文地址:https://www.cnblogs.com/fanxinguu/p/4399856.html