To share code and resources between my app and extensions, I embed a Cocoa Touch Framework
in my project, this framework contains some resources like image and xib files.
My question is: how do I access those resources from may main app and extensions?
I used to use this method: iOS 8 Extension: how to use xib inside Cocoa Touch Framework in extensions?
but this will make a copy to all resources in app's bundle and extensions' bundle, which is not a good repeat.
Is there a better way?
Update:
Now my main app can use code like this to access resource in frameworks:
+(NSBundle*)frameworkBundle
{
NSString *frameworkDirPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *frameworkBundlePath = [frameworkDirPath stringByAppendingPathComponent:@"MyFramework.framework"];
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
return frameworkBundle;
}
but this doesn't work for extensions.
Try this:
NSBundle *frameworkBundle = [NSBundle bundleForClass:[AnyClassFromFramework class]];
This worked for me:
NSBundle * frameworkBundle = [NSBundle bundleWithIdentifier:@"<framework-bundle-identifier>"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With