Search code examples
iphoneobjective-cioscocoaipad

How to load resources from external framework


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


Solution

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