Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plist的bundle路径 #106

Open
rjinxx opened this issue Jan 22, 2018 · 4 comments
Open

Plist的bundle路径 #106

rjinxx opened this issue Jan 22, 2018 · 4 comments

Comments

@rjinxx
Copy link

rjinxx commented Jan 22, 2018

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

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

[NSBundle bundleForClass:[self class]]
@MemoryReload
Copy link

@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.

@rjinxx
Copy link
Author

rjinxx commented Jan 23, 2018

@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.

@MemoryReload
Copy link

MemoryReload commented Jan 24, 2018

@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. : )

@rjinxx
Copy link
Author

rjinxx commented Jan 25, 2018

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants