+ 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