What is the application Bundle and Resources folder

162 views Asked by At

My question is about the application bundle in a project. I was reading about that and can understand some basic things (I'm not a native english speaker). I can understand that the resources folder is used to hold the files that will be used in the project, e.g. media files (images, audio, video, etc.) and should be in the application bundle to be identified.

So, what is the point if I want to use images and another resources in my project? In my other related question, I can't use them by referencing with NSImage imageNamed:.

I have used the following with no success loading my files:

  • NSBundle methods
  • imageNamed:@"string" with/without file extension
  • the images are in resources folder

I'm learning Cocoa and Objective-C, and of course this is different to C++ or Java when I want to create an ImageIcon or a QImage.

1

There are 1 answers

0
Sam Spencer On

I may not have completely understood the issue, so correct me if I am wrong. I believe the problem has to do with your image's target membership or how you're retrieving the image in your code.

Adding an image to your project target will appropriately copy the resource at compile time. To add the image to your target, select it in the file navigator and then reveal the Utilities Panel. On the Utilities Panel, select the File Inspector Tab. Look for the Target Membership section and ensure that the image is selected for the desired targets:

Xcode 5 Target Membership

Do you mean that you can't use the NSImage imageNamed: method to retrieve resources? If so, you can retrieve the resource like this (from the main resource bundle):

NSString *imageName = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"];
NSImage *imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];

It also looks like you already have a good answer to your other related question.