I have build an external framework, and I am trying to utilize some images which are in the resource directory of the framework. The framework is not being copied within the application but rather just referenced to it. How can I utilize UIImage accordingly from xyz.framework resource folder?
Thanks
It's called contentsOfFile , and here it is in action: if let filepath = Bundle. main. path(forResource: "example", ofType: "txt") { do { let contents = try String(contentsOfFile: filepath) print(contents) } catch { // contents could not be loaded } } else { // example.
NSBundle(IntPtr) A constructor used when creating managed representations of unmanaged objects; Called by the runtime. NSBundle(NSObjectFlag) Constructor to call on derived classes to skip initialization and merely allocate the object.
To include a framework in your Xcode project, choose Project > Add to Project and select the framework directory. Alternatively, you can control-click your project group and choose Add Files > Existing Frameworks from the contextual menu.
The bundle object provides a single interface for locating items, taking into account the bundle structure, user preferences, available localizations, and other relevant factors. Any executable can use a bundle object to locate resources, either inside an app's bundle or in a known bundle located elsewhere.
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/
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