Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8: get resource from Cocoa Touch Framework

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.

like image 218
CarmeloS Avatar asked Oct 19 '14 04:10

CarmeloS


2 Answers

Try this:

NSBundle *frameworkBundle = [NSBundle bundleForClass:[AnyClassFromFramework class]];
like image 154
Tony Avatar answered Oct 21 '22 14:10

Tony


This worked for me:

NSBundle * frameworkBundle = [NSBundle bundleWithIdentifier:@"<framework-bundle-identifier>"];
like image 45
iljer Avatar answered Oct 21 '22 13:10

iljer