alibaba/BeeHive

Plist的bundle路径

Opened this issue · 4 comments

NSString *plistPath = [[NSBundle mainBundle] pathForResource:xx ofType:@"plist"];

读取plist的bundle路径是否应该改成:

[NSBundle bundleForClass:[self class]]

@RylanJIN I think both is OK. It only differs when you put BeHive in an independent bundle, maybe, a framework.

the apple's doc about bundleForClass: said below:

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 aClass was not dynamically loaded or is not defined in a framework.

This method creates and returns a new NSBundle object if there is no existing bundle associated with aClass. Otherwise, the existing instance is returned.

@MemoryReload Yes, as you mentioned, if we put BeHive in an independent bundle:
[NSBundle mainBundle] pathForResource would return nil, but [NSBundle bundleForClass:[self class]] works.
Plus, if we don't put BeHive in an independent bundle, [NSBundle bundleForClass:[self class]]works as well, so I guess it would be better to use the later one.

BTW, If you check out some popular 3rd repos such as MJRefresh, they also apply the second format.

@RylanJIN One thing I have to say, If your framework is not dynamic, your class will be linked into the executable image. So it will be loaded from main bundle too. That will be tricky unless you make this class to be dynamically loaded from another bundle (maybe a dynamic framework, I think). But in my opinion, that's really unnecessary. : )

@MemoryReload In my case, if I pod BeeHive with use_framework! setting, [NSBundle mainBundle] would return nil, thus, no module from plist gets registered. So, what's the explanation on this?