How to load resources from external framework
What you need to do is load the bundle for the framework, and then access the resources using the NSBundle object.
For example, if there is a framework that defines a class "FrameworkClass", we can do:
NSBundle *frameworkBundle = [NSBundle bundleForClass:[FrameworkClass class]];
NSString *resourcePath = [frameworkBundle pathForResource:@"an_image" ofType:@"jpeg"];
UIImage *image = [UIImage imageWithContentsOfFile:resourcePath];
That should more or less do what you want.
You can refer to Framework resources as follows :
[[NSBundle mainBundle] pathForResource:@"FI.framework/Resources/FileName"
ofType:@"fileExtension"];
Note, here FI is your framework name.
Ref. Link : http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/
Swift 4/5:
let bundle = Bundle(for: type(of: self))
// let bundle = Bundle(for: ClassOfInterest.self)) // or by pointing to class of interest
let path = bundle.path(forResource: "filename", ofType: "json")!
let url = URL(fileURLWithPath: path)
let data = try! Data(contentsOf: url)
This is from inside framework / unit tests, in production code you don't want to force try and force unwrap.
Swift 3:
let bundle = Bundle(for: SomeFrameworkClass.self as AnyClass)
if let path = bundle.path(forResource: "test", ofType: "png") {
if let image = UIImage(contentsOfFile: path) {
// do stuff
}
}