+ 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