IOS_基础类库之NSBundle

这篇博客详细介绍了NSBundle类库在iOS开发中的使用,包括如何创建和获取NSBundle对象,如通过mainBundle、path、URL等方式。还讨论了如何获取资源、检查加载状态、获取bundle信息以及与资源路径相关的方法。对于iOS开发者来说,理解NSBundle是掌握应用程序资源管理的关键。
摘要由CSDN通过智能技术生成
1、使用类方法创建一个NSBundler对象
+ (NSBundle *)mainBundle;
eg:[NSBundle mailBundle];
2、使用路径获取一个NSBundle 对象,这个路径应该是一个目录的全路径
+ (NSBundle *)bundleWithPath:(NSString *)path;
eg:  
NSString *path = [mailBundle resourcePath];
  NSBundle *language = [NSBundle bundleWithPath:path];
3、使用路径初始化一个NSBundle
- (id)initWithPath:(NSString *)path;


4、使用一个url 创建并初始化一个NSBundle对象(这是一个类方法)
注:这里的url 是一个特殊的 文件url路径
+ (NSBundle *)bundleWithURL:(NSURL *)url
5、使用一个url 初始化一个NSBundle对象
注:这里的url 是一个特殊的 文件url路径
- (id)initWithURL:(NSURL *)url
6、根据一个特殊的class 获取NSBundle
+ (NSBundle *)bundleForClass:(Class)aClass;
eg:根据当前的class 获取一个NSBundle // 获取当前类的NSBundle
NSBundle *bud = [NSBundle bundleForClass:[self class]];
NSLog(@"bud==%@",bud);
输出结果如下:
NSBundle </Users/ctrip1/Library/Application Support/iPhone Simulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app>
7、获取特定名称的bundle
+ (NSBundle *)bundleWithIdentifier:(NSString *)identifier;
8、使用NSBundle 获取所有的bundle信息(由于ios安全沙盒的限制,所有的获取的资源,是应用程序的资源)
注:官方标注,获取所有的非framework 的bundle;
+ (NSArray *)allBundles;
eg:
NSArray *array = [NSBundle allBundles];
NSLog(@"array===%@",array);
打印的结果如下:
array===(
    "NSBundle </Users/ctrip1/Library/Application Support/iPhone Simulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app> (loaded)"
)
9、获取应用程序加载的所有framework的资源,
+ (NSArray *)allFrameworks;
eg:
NSArray *array = [NSBundle allFrameworks];
NSLog(@"%@",array);
输出的结果如下:(
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/XPCObjects.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/JavaScriptCore.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/AggregateDictionary.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/WebCore.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/SpringBoardServices.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值