bundleForClass的返回


+ bundleForClass:

Return Value

The NSBundle object that dynamically loaded aClass(a loadable bundle), the NSBundle object for the framework in which aClass is defined, or the main bundle object if a Class was not dynamically loaded or is not defined in a framework.


如上是bundleForClass的官方说明。

在实际使用中我的类与app是这么一层关系: class->static library->framework->app

那这种情况下这个class到底算不算framework定义的呢?

特意写了一个demo,分别在app,framework(dynamic library),static lib中定义了三个类,并调用bundleForClass方法输出,结果如下:

app - app bundle

framework - framework bundle

static lib - app bundle

再将framework build setting中的Mach-O Type改为static library,结果如下

app - app bundle

framework - app bundle

static lib -app bundle

所以只要是静态库,都属于官方说明中的最后一种情况:

the main bundle object if a Class was not dynamically loaded or is not defined in a framework.


至于静态库,动态库,framework这些概念的解释,我找到一篇很好的博文:

https://skyline75489.github.io/post/2015-8-14_ios_static_dynamic_framework_learning.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容