NSBundle类的介绍

来源:互联网 发布:淘宝店铺转让新规 编辑:程序博客网 时间:2024/04/28 06:28

当创建一个应用时,系统存储了应用相关联的所有数据(其中包括图片、本地化字符串、图标等),将这些内容放入一个称为应用包(application bundle)的包中。为了访问应用中的这些资源,需要熟悉NSBundle类

  1. 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹
  2. 利用mainBundle就可以访问软件资源包中的任何资源
  3. 我自己电脑上模拟器路径(做个笔记,以免自己忘了)
    /Users/apple/Library/Developer/CoreSimulator/Devices/A90317E7-5C5A-4EAC-A3EC-26AC757F23DA/data/Containers/Data/Application/
  4. 可以使用如下方法找到模拟器路径
    NSLog(@”Documents Directory: %@”, [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);

代码的使用

NSBundle *bundle = [NSBundle mainBundle];//获取plist文件的全路径//pathForResource:传入文件名称 ofType:传入扩展名 NSString *path = [bundle pathForResource:@"imageData" ofType:@"plist"];//获取图片文件的全路径//可以将pathForResource的参数传入一个带扩展名的文件名称,ofType直接传入nil即可NSString *path = [bundle pathForResource:@"aa.png" ofType:nil];
0 0
原创粉丝点击